Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcc5018's avatar

SpatieMedialibrary - for filament not uploading

So i suspect that I have something configured improperly, but I dont have a clue what is missing.

Between FILAMENT_FILESYSTEM_DISK and the spatie default config

'disk_name'                                 => env('MEDIA_DISK', 'public'),

    /*
     * The maximum file size of an item in bytes.
     * Adding a larger file will result in an exception.
     */
    'max_file_size'                             => 1024 * 1024 * 10, // 10MB


and filesystem config:

  'disks' => [

        'local'  => [
            'driver' => 'local',
            'root'   => storage_path('app'),
            'throw'  => false,
        ],
        'media'  => [
            'driver'     => 'local',
            'root'       => public_path('media'),
            'url'        => env('APP_URL').DIRECTORY_SEPARATOR.'media',
            'visibility' => 'public',
        ],
        'public' => [
            'driver'     => 'local',
            'root'       => storage_path('app/public/'),
            'url'        => env('APP_URL').'/storage',
            'visibility' => 'public',
            'throw'      => false,
        ],

I am not sure if uploaded files are going in public/storage, public/images, resources/___ or storage/___

In this particular instance I am trying to set a featured image for my hobby model: (has media/interacts with media are set

public function registerMediaCollections(): void
    {
        $this->addMediaCollection('hobby_img')
             ->useFallbackUrl('https://placeholder.co/300x300');

    }


    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb')
             ->width(100)
             ->useFallbackUrl('https://placeholder.co/100x100')
             ->keepOriginalImageFormat()
             ->nonQueued();
        $this->addMediaConversion('index')
             ->fit(Fit::Contain, 300, 300)
             ->useFallbackUrl('https://placeholder.co/250x250')
             ->keepOriginalImageFormat()
             ->nonQueued();
        $this->addMediaConversion('profile')
             ->width(500)
             ->useFallbackUrl('https://placeholder.co/500x500')
             ->keepOriginalImageFormat()
             ->nonQueued();
    }

In my hobbyResource with filament I have

  Section::make('Featured Image')
                                ->schema([
                                    SpatieMediaLibraryFileUpload::make('hobby_img')
                                                                ->label('Featured Image')
                                                                ->collection('hobby_img'),
                                ]),

Each hobby should have one hobby_img but i want all hobby imgs grouped together in a folder, as with user-avatars, and other such images.

When i attempt to upload, The upload shows the photo but has an "error during upload- tap to retry " message. But i have no idea how to figure out what the error is and could use some assistance.

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like you're having trouble with file uploads using Spatie's Media Library in combination with Filament. The error message "error during upload - tap to retry" suggests that there might be an issue with the server-side processing of the upload request.

Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Check the Disk Configuration: Ensure that the disk you're using for media uploads is correctly configured in config/filesystems.php. Based on your configuration, it looks like you're using the public disk. Make sure that the MEDIA_DISK environment variable is set to public in your .env file:

    MEDIA_DISK=public
    
  2. Permissions: Check the permissions of the storage/app/public directory. The web server should have write permissions to this directory. You can set the correct permissions using the following commands:

    php artisan storage:link
    chmod -R 775 storage/app/public
    chown -R www-data:www-data storage/app/public
    

    Replace www-data:www-data with the appropriate user and group that your web server runs under.

  3. Debugging: To find out what the error is during the upload, you can check the Laravel log files in storage/logs/. Additionally, you can open the browser's developer tools (usually F12) and check the Network tab for the request that fails. The server response might contain more details about the error.

  4. File Size Limit: Ensure that the file you're trying to upload does not exceed the maximum file size defined in the Spatie Media Library configuration ('max_file_size' => 1024 * 1024 * 10). Also, check your PHP configuration (php.ini) for upload_max_filesize and post_max_size to ensure they are not limiting the file size.

  5. Media Collection Configuration: If you want all hobby images grouped together in a folder, you can use the useDisk method on the media collection to specify a custom disk that points to a specific directory:

    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('hobby_img')
             ->useDisk('media')
             ->useFallbackUrl('https://placeholder.co/300x300');
    }
    

    Make sure to create a media disk configuration in config/filesystems.php if you haven't already.

  6. File Upload Component: Ensure that the SpatieMediaLibraryFileUpload component is correctly set up in your Filament resource. The collection method should match the collection name you defined in your model's registerMediaCollections method.

If after following these steps the issue persists, you may need to provide more specific error messages or logs to further diagnose the problem.

jcc5018's avatar

apparently the issue was a lack of a temp directory defined in php.ini...

you know how long i have been unable to get images to upload ? Because of a stupid config file in php.

see github if anyone else has this issue.

2 likes

Please or to participate in this conversation.