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).
No description
5 Replies
awcodes
awcodes15mo ago
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.
Diogo Gomes
Diogo GomesOP15mo ago
@awcodes is there a method on the Field where I can set the url?
awcodes
awcodes15mo ago
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.
Diogo Gomes
Diogo GomesOP15mo ago
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.
awcodes
awcodes15mo ago
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.
Want results from more Discord servers?
Add your server