1

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:

Controller

//$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");
//dd($data);
//dd($test);

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

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

screenshot

Robert Longson
  • 118,664
  • 26
  • 252
  • 242
maki10
  • 553
  • 2
  • 11
  • 4
    you took a photo of your monitor?!?!? –  Jun 26 '16 at 23:07
  • Really?! When you sharing photo with your contacts it is twice easier to take a picture and not take ss. You can see the error i will not provide ss.. – maki10 Jun 26 '16 at 23:13
  • This is how i do in Laravel 5.1 [http://stackoverflow.com/questions/36778167/download-from-laravel-storage-without-loading-whole-file-in-memory](http://stackoverflow.com/questions/36778167/download-from-laravel-storage-without-loading-whole-file-in-memory) – maki10 Jun 29 '16 at 08:17

1 Answers1

1

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
dd($files);

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.

Bosko Stupar
  • 143
  • 1
  • 1
  • 8