maki10 maki10 - 1 year ago 166
PHP Question

Laravel AWS Download

I started a new project via Laravel 5.1 and came to the part where I need to download a file with s3 (AWS). I noticed that keeps files in xml format.

How do I download a file to s3? Here's what I have so far:


//$key = urldecode($key);

//This way found file as .xml but can't get zip file?!
$key = str_replace('.zip', '.xml', $firmware->key);
$test = Storage::disk('s3')->get('db/'.$key);

//dd($test); this get:
FileNotFoundException in FilesystemAdapter.php line 58:
db/Toshiba\07GAH\TOSHIBA MK8007GAH-BG002H0-Y6HNW0EOW.xml*

$data = (array) simplexml_load_string($test) or die("Can't read XML for $manifest");

return response()->download('db/'.$data['key']);

This is error I see in the browser when in db change "\" in "/"


Answer Source

The error is self explained. You get that exception FileNotFoundException because .. well file was not found on the server with provided name.

You should first check if file exists on the server and handle it that way Laravel documentation for File System. If you go a bit further down on that documentation you have section on how to list all files from directory tho in your case it would be something like

$files = Storage::disk('s3')->files(); //or allFiles() return sub dir files also

this is for debuging and to see what you're doing wrong. With data that you get from it, you can fix your errors and continue with building your app.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download