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

basherdesigns's avatar

Error 500 when hitting Save on form using SpatieMediaLibraryFileUpload

Laravel v11.7.0 / FilamentPHP v.v3.2.79

All functionality works correctly on dev environment using CloudFlare R2 as storage. Moved to Production and when I add an image, it uploads to R2 bucket temp directory /livewire-tmp/ymWaqsRePMGAOC44Qik8veBKZJvozU-metaaW1hZ2UtYXNzZXQuanBn-.jpg (for example) Then hit Save on form and get 500 Error.

Log shows:

production.ERROR: Illuminate\Translation\PotentiallyTranslatedString::__toString(): Return value must be of type string, null returned {"userId":2,"exception":"[object] (TypeError(code: 0): Illuminate\Translation\PotentiallyTranslatedString::__toString(): Return value must be of type string, null returned at /home/forge/domain.com/vendor/laravel/framework/src/Illuminate/Translation/PotentiallyTranslatedString.php:89)
[stacktrace]

Image is not uploaded from temp directory to r2 public bucket and record is not saved in the media table for the image on the model.

Here is my form element:

SpatieMediaLibraryFileUpload::make('location-images')
                ->imageEditor()
                ->disk('r2images')
                ->label('Location Photos')
                ->columnSpanFull()
                ->collection('location-images')
                ->multiple()
                ->image()
                ->reorderable(),

If I remove the image() function, the model saves with Save notification but image is not saved to correct bucket and nor added to the media table.

What am I missing here?!

0 likes
8 replies
LaryAI's avatar
Level 58

The error you're encountering seems to be related to a translation string issue in Laravel, which is causing a 500 Internal Server Error. This can happen if a translation key is missing or if there's an issue with the translation files.

Here are a few steps to troubleshoot and potentially resolve the issue:

  1. Check Translation Files: Ensure that all necessary translation keys are present in your translation files. Specifically, look for any keys related to the Spatie Media Library or FilamentPHP that might be missing.

  2. Debug the Error: Add some debugging to see exactly where the error is occurring. You can do this by temporarily adding some logging in the PotentiallyTranslatedString.php file around line 89 to see what value is being returned.

  3. Check Disk Configuration: Ensure that your r2images disk is correctly configured in your config/filesystems.php file. It should look something like this:

    'disks' => [
        'r2images' => [
            'driver' => 's3',
            'key' => env('R2_ACCESS_KEY_ID'),
            'secret' => env('R2_SECRET_ACCESS_KEY'),
            'region' => env('R2_DEFAULT_REGION'),
            'bucket' => env('R2_BUCKET'),
            'url' => env('R2_URL'),
            'endpoint' => env('R2_ENDPOINT'),
        ],
    ],
    
  4. Check Media Library Configuration: Ensure that your Spatie Media Library is correctly configured to use the r2images disk. This can be done in the config/media-library.php file.

  5. Check for Null Values: The error message indicates that a null value is being returned where a string is expected. Ensure that all necessary fields and values are being set correctly before saving the model.

  6. Update Dependencies: Ensure that all your dependencies are up to date. Run composer update to update your packages to the latest versions.

  7. Form Element Configuration: Ensure that your form element is correctly configured. Here is a slightly modified version of your form element with some additional checks:

    SpatieMediaLibraryFileUpload::make('location-images')
        ->imageEditor()
        ->disk('r2images')
        ->label('Location Photos')
        ->columnSpanFull()
        ->collection('location-images')
        ->multiple()
        ->image()
        ->reorderable()
        ->rules('required'), // Add validation rules if necessary
    
  8. Check for Middleware Issues: Sometimes middleware can interfere with file uploads. Ensure that there are no middleware that might be causing issues with the file upload process.

If none of these steps resolve the issue, you might want to provide more detailed logs or code snippets to get more specific help. Additionally, consider reaching out to the maintainers of the Spatie Media Library or FilamentPHP for further assistance.

basherdesigns's avatar

Just tried using 'local' disk instead of Cloudflare R2 bucket and getting the same error, so doesn't seem to be disk related. Has to be something with Filament on the Prod server.

citricguy's avatar

Starting to drill down on what is causing it. I don't have a solution yet, but I seem to be running into the same issue.

It looks like the image() call is causing the error.

FileUpload::make('logo')
   ->disk('public')
   ->directory('logos')
   ->visibility('public')
   ->image()  // <----- This is triggering the error
   ->imageEditor(),
1 like
basherdesigns's avatar

@citricguy I have not been able to find a solution! removing the ->image() doesnt' give me a 500 error but also doesn't save to the media table or bucket! Everything works great on my MBP with Herd. But not produciton server..

1 like
basherdesigns's avatar

Also, I posted on Filaments Discord channel but haven't gotten any solution there either. Not sure how to escalate this issue now that its not just myself!

1 like
basherdesigns's avatar
basherdesigns
OP
Best Answer
Level 5

Ok, I fixed the issue! Wow It was an Client IP Address Filtering API access issue for the R2 bucket. There was an IP range in the Include list. Which the server was not in. Added the server IP to the API address filter and worked.! Go to R2 Object Storage - Overview, then top right, click Mange R2 API tokens. Wow I'm not sure where this IP range came from but... finally I can upload to R2 buckets from Filament!

Please or to participate in this conversation.