spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

Uploading webp files in Vapor throws an error #3709

Open josiahmann opened 2 months ago

josiahmann commented 2 months ago

When using the addToMediaFromURL method, I'm receiving a Could Not Load Image error on the server, but not locally (I'm using Laravel Vapor) and not with other image formats.

The code below is where the error is occuring and that code is receiving an absolute file path to the image in s3, which is available.

public function addToMediaLibrary($file_path) { $media = $this->addMediaFromUrl($file_path) ->toMediaCollection("", 's3'); return $media; }

As an example the file path when logged out is https://s3.sitesforsaas.com/tenants/d221c93a-3757-466c-bf83-b74a9ee64c04/sites/9cfc24c7-cb2a-4c5a-8c0f-73ecdc79c166/2024/09/4e9854b0-4f2d-4931-a726-01f557bd7fc6.webp, but the error is looking for the image in local 'tmp' storage for some reason.

Could not load image at path/tmp/storage/tenantd221c93a-3757-466c-bf83-b74a9ee64c04/media-library/temp/j7pNMerUdReNx9MfAG5rKjcmGHWu4i99/LM2UYMTcYU0BO8sLsTfeOBpS9eXximejlarge.webp`",

StyxUA commented 4 weeks ago

Could you show more log entries around this error?

maliknikolaj commented 1 week ago

I'm not sure you have the same problem as me but I had to alter dockerfile used by Vapor runtime since webp support is not enabled by default. I have changed GD php extension to be compiled with webp support (and jpeg because jpeg somehow was disabled when I had enabled webp).

File: production.Dockerfile in the project root:

FROM laravelphp/vapor:php83

RUN apk --update add libwebp-dev
RUN apk --update add libjpeg-turbo-dev
RUN docker-php-ext-configure gd --with-webp --with-jpeg
RUN docker-php-ext-install gd

COPY . /var/task