Elliot_putt's avatar

Production FIle Upload errors

Hi All,

I am Using Spatie Media Library and having trouble uploading images to a production app.

I Have 2 identical forge websites pulling from the same GitHub repo one will allow me to upload files and the other returns the following error.

 production.ERROR: Url cannot be reached {"userId":1,"exception":"[object] (Spatie\MediaLibrary\MediaCollections\Exceptions\UnreachableUrl(code: 0): Url `**/storage/docs/test/bsqXo4H5nAoNKXCDS2iseNe3heCTtNGbe2w0Lx4w.pdf` cannot be reached at **/vendor/spatie/laravel-medialibrary/src/MediaCollections/Exceptions/UnreachableUrl.php:9)

code in question however this works locally and in one other production app.

$fileName = str_replace([" ", '-'], "_", $file->getClientOriginalName());
                $fileHash = Storage::disk('documents')->putFile(substr($fileName, 0, strpos($fileName, '.')), $file);
                $media = $this->model->addMediaFromUrl(Storage::disk('documents')->url($fileHash))->toMediaCollection($this->collection);
0 likes
14 replies
illuminatixs's avatar

I assume the “**” is just you removing information for the path: Check if storage:link was ran for your production environment, looks like public/storage isn't available for your production environment.

Otherwise, if I assumed incorrectly before: Why are you prefixing the route with **?

Elliot_putt's avatar

@illuminatixs HI, this is just me removing the URL of the site imagine instead it's like

 https://test.com/storage/docs/test/bsqXo4H5nAoNKXCDS2iseNe3heCTtNGbe2w0Lx4w.pdf

I have run the storage link sorry!

illuminatixs's avatar

@Elliot_putt Sorry for the obvious questions, but most of the time these errors are hidden in these things:

Have you confirmed the "putFile" action is actually writing the data to the expected path?

If not: Possibly permissions issues on server.

Are you not getting a SSL related issue while addMediaFromurl is attempting to call the URL?

If so: Check if your SSL-cert is valid for your site.

Are you blocking requests without headers / user-agents?

if so: Add custom downloader: Spatie documentation

Elliot_putt's avatar

@illuminatixs No worries I understand haha it can be a pain.

Yes if it visits the URL where the error fails it will literally pull up the file from my storage it's so weird.

the SSL cert is indeed valid never thought to check this thanks!

how will I know if I'm blocking requests without headers?

Tray2's avatar

@Elliot_putt Have you checked that you have the correct permissions on the storage directory?

Elliot_putt's avatar

@Tray2 Hi Tray,

Do you know how I can see if I have the correct permissions?

It has been working previously and then with no code changes suddenly stopped.

Tray2's avatar

@Elliot_putt What does the rest say?

drwxr-xr-x   6 tray2  staff     192 Oct 26 18:59 storage

That means that the owner has read write execute permissions, the group has read and execute, and all have read and execute.

Elliot_putt's avatar

@Tray2 Got this error hopefully this solves it! Thanks for all your help chmod: missing operand after ‘664’

Please or to participate in this conversation.