Search code examples
laravellaravel-filesystem

File not downloading laravel 5.6


I've read other questions and implemented answers but haven't had any success.

Here's the error: enter image description here

files in database, and locally: enter image description here

here's my form: enter image description here here's my file-controller: enter image description here

The flow is I upload a file, it is stored into the database, and locally, the files locally work properly. I implemented the download attribute and was able to get actual files, but those files and that process was scrapped because the files downloaded, while they had the correct names and mime types, the file had a error like "could not open file".

I am primarily using the download method in the filecontroller which you can see above, I used some ideas for getting the actual path to the file, as that seems to be the issue, but even using the storage_path method I'm getting this error.

Thanks!


Solution

  • I didn't understand the pathing for filestorage enough, and was therefor obviously getting the incorrect paths to the file being stored.

    For example, the storage_path method returns the path to storage, I thought it was going to give me the exact path to the file. Once figuring this out I was able to navigate and fix my issues.

    filecontroller line 52: storeAs was storing to a redundant path, i made it as '/upload'/

    filescontroller@download return response()->download(storage_path("app/upload/{$file}"));

    following the paths where files were being saved locally, I was able to fix this issue.