0

After storing some files on amazon S3 I would like to be my users to be able to download the files they uploaded to S3. Reading laravel docs shows this:

$contents = Storage::get('file.jpg');

This will return me the contents of the file. I would like to offer the file as a download to the user. Currently I'm storing the name in my database. File is located on S3.

Did I need to store the MIME type in my database too or is there a smarter way to retrieve files from S3 and offer them as download?

peke_peke
  • 441
  • 7
  • 21
  • If you're offering it as a download, you may want to read up on generating signed URLs with S3, and then just redirecting your user to that URL. It's a bit more work to setup, but then the download doesn't have to go through your own script. – Here2Help Mar 02 '16 at 17:45
  • Is there a library to deal with signed URLs? I found this, but I have no idea what the $value and $key stands for: http://stackoverflow.com/questions/25323753/laravel-league-flysystem-getting-file-url-with-aws-s3 – peke_peke Mar 02 '16 at 18:21
  • Yes. Use AWS' own SDK. https://aws.amazon.com/sdk-for-php/ – Here2Help Mar 02 '16 at 18:23
  • https://docs.aws.amazon.com/aws-sdk-php/v3/guide/service/s3-presigned-url.html – Here2Help Mar 02 '16 at 18:24
  • hmm stands key for private or public key? Where to specify the file I would like to download... – peke_peke Mar 02 '16 at 18:27

0 Answers0