laravel-medialibrary: Upgraded to v10 and it's completely broken for me... weird UUIDs and empty files

I recently upgraded from PHP 7.4 to PHP 8.1, upgraded Laravel from v8 to v9 (via Laravel Shift), and upgraded media library from v9 to v10.

Everything else is working great except this library.

I’m also using Media Library Pro components. When uploading a file, the files are empty and both GD and Imagick complain due to the file being 0 bytes.

GD gives me the following:

Unsupported image type application/x-empty. GD driver is only able to decode JPG, PNG, GIF, BMP or WebP files.

Imagick gives me the following:

Unable to read image from path (/tmp/Glide8fN9rc).

This is what my storage directory looks like after a clean install:

image

This is what it looks like after simply dragging a file into the pro collection component (without saving the form):

image

And if I click save, this is what it looks like:

image

Livewire Component:

<?php

namespace App\Http\Livewire\Orders;

use App\Models\Order;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
use Spatie\MediaLibraryPro\Http\Livewire\Concerns\WithMedia;

class PhotoComponent extends Component
{
    use AuthorizesRequests, WithMedia;

    public Order $order;

    public $mediaComponentNames = ['photos'];

    public $photos;

    public function save()
    {
        $this->authorize('update', $this->order);

        $this->order->syncFromMediaLibraryRequest($this->photos)->toMediaCollection('photos');

        $this->order->refresh();

        $this->dispatchBrowserEvent('photos-saved');
    }

    public function render()
    {
        return view('livewire.orders.photo-component');
    }
}

This is my composer.json file:

    "require": {
        "php": "^8.0.2",
        "doctrine/dbal": "^3.3",
        "guzzlehttp/guzzle": "^7.4",
        "laravel/framework": "^9.7",
        "laravel/sanctum": "^2.15",
        "laravel/tinker": "^2.7",
        "laravel/ui": "^3.4",
        "livewire/livewire": "^2.10",
        "nesbot/carbon": "^2.57",
        "spatie/browsershot": "^3.52",
        "spatie/laravel-medialibrary": "^10.3",
        "spatie/laravel-medialibrary-pro": "^2.3",
        "spatie/laravel-permission": "^5.5",
        "spatie/laravel-ray": "^1.29"
    },

Model:

<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class Order extends Model implements HasMedia
{
    use HasFactory, InteractsWithMedia;

    protected $guarded = [];

    protected $with = ['meta'];

    public $timestamps = false;

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('preview')
            ->fit(Manipulations::FIT_CROP, 300, 300)
            ->nonQueued();

        $this->addMediaConversion('normal')->fit(Manipulations::FIT_CONTAIN, 1152, 864);
    }

    public function meta()
    {
        return $this->hasOne(OrderMeta::class)->withDefault();
    }
}

View:

<x-modal wire:ignore.self id="modal-photos" size="modal-lg">
    <x-slot name="header">
        <h5 class="modal-title">Manage Photos</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
    </x-slot>
    <x-slot name="body">
        <form wire:submit.prevent="save" id="form-photos" autocomplete="off">
            <x-media-library-collection name="photos" :model="$order" collection="photos" rules="mimes:jpeg,png|max:3072" />
        </form>
    </x-slot>
    <x-slot name="footer">
        <button type="submit" class="btn btn-primary" form="form-photos">
            <span wire:loading.delay wire:target="save" class="spinner-border spinner-border-sm"></span>
            Save
        </button>
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
    </x-slot>
</x-modal>

Database:

image

I’m not doing anything out of the ordinary here, I have no idea why it broke? I’ve cleared caches, reinstalled, cloned from source, etc.

Another thing is that I have a conversion (normal) that should be queuing (see registerMediaConversions on model) into the jobs table on the database but no job is ever created.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 30 (8 by maintainers)

Most upvoted comments

The solution you came to @ryanmortier seems to be just not using the pro components?

Yeah pretty much. I’m hoping to one day add them back in but there is like zero support for these components and I don’t have time to dig into it.

Yea… It’s tough because when you pay $300 for a license annually, you expect to be able to use it.

I’ll be taking a look at this next week (sorry for the wait). Could anybody confirm that these issues are occurring when you use our demo app? A minimal app that showcases the problem would help a lot.

The solution you came to @ryanmortier seems to be just not using the pro components?

Yeah pretty much. I’m hoping to one day add them back in but there is like zero support for these components and I don’t have time to dig into it.

Yea… It’s tough because when you pay $300 for a license annually, you expect to be able to use it.

I’m having this issue as well since doing updates. Pretty massive issue since, as you say, this is licensed software.

Has anybody had any update on this?

Thanks for the incredible package everyone at Spatie!

I’m getting the exact same error. My assets SHOULD be saved in a “bucket_assets” directory. When using the pro react component to select a file from my computer, my storage folder looks like so:

image

Once I click upload, it then looks like this:

image

Notice at the root of my storage directory I’m left with a random directory with a uuid as a name, with an image inside it. Yet the rest is moved correctly to the bucket_assets directory.

This is frustrating as this random folder never seems to get garbage collected, so it’ll just clog up the storage folder. I’ve also noticed that the media-library/temp directory is never used.