File uploads correctly but when trying in view throws 404
Hello. I suppose I may be missing something very basic, but I cannot find the solution.
I am using Spatie Media Library to manage the PDF's that my application users can upload.
I have created this:
It uploads the file correctly and I can see it in storage\app\public\3\name_of_pdf_file.pdf.
But when I go to the view form of the resource, and I click the link to download or to open it, it throws an error:
Not Found
The requested URL was not found on this server.
It is trying to open:
http://localhost/storage/3/name_of_pdf_file.pdf
Any hint of what I am doing wrong?
By the way, my filesystems.php file has the default information:
1 Reply
I found one part of the solution, for the local environment.
I am using windows and my local app url is ==> http://127.0.0.1:8000/
So I changed the localhost with that and it works. Then I went to .ENV file and put this:
APP_URL=http://127.0.0.1:8000
Now it is working locally.
In production, up in the cloud, it is not working. I am using Forge and I deploy, do the same as locally and it does not work.
Same behaviour. It uploads perfectly, and I can see the pdf file inside the folder storage/app/public/3/name_of_pdf_file.pdf
but the link tries to open:
https://apps.geslem.com/storage/3/name_of_pdf_file.com
And it thows a 404 this time.
Up in the production server I used the
php artisan storage:link
command.
Is happens with FileUpload, too.
It uploads correctly, I can see the file in the storage\app\public folder
the symlink has been made, but no results.
For certain that it must be something I am missing.
Well, after a lot of struggle and testing I have found what happened.
It looks as if the deployment script in my Forge account created the symlink badly.
I had to delete the public/storage folder (with sudo permissions) and re-run
php artisan storage:link
That solves all the problem both with normal FileUpload and with SpatieMediaLibraryFileUpload
Nearly got crazy and hope it helps someone else.