File Upload on local non-public disc
I have a form with one file upload with
disk('local')
because those files can't be access publicaly.
But I do want the logged in user to be able to download those files.
But right now it does not work (screenshot attached).5 Replies
Local doesn’t have a url, which means files stored there can’t be rendered in the FileUpload. Look into using a private disk instead of the local disk.
@awcodes is there a method on the Field where I can set the url?
There’s no url to set. Anything directly in the local disk isn’t included when you do storage:link. If you use a private disk and tell the file upload to ->visibilty(‘private’) it will work.
sorry @awcodes but I can't make this work. I've tried a lot of things but nothing works. It uploads the file fine. But the frontend keeps spinning.
And I don't understand why I don't have to set a route to serve the file, that it's stored on a private local disk.
There is an actual disk in laravel called “local” it by default will never have a an accessible url, only a file path. And file paths in this context aren’t resolvable from an html img tag’s src. So what you’d technically need is a custom disk that is basically the same as the public disk but set as private in the disks config inside of config/filesystem.php. When you have a private disk and set file upload field to be visibility private it creates a temporary signed url so that it can be rendered via html.