Unable to download file from s3 using return response()->download($file);

Saqueib

I am uploading files tos3 I want it to download securely using following code in my controller, but it's not working.

I am using Laravel 5.5 and files visibility is not public on s3.

if( Storage::disk('s3')->exists($file_path) ) {
      $file =  Storage::disk('s3')->get($file_path);
      return response()->download($file);
}

abort(404, 'File not found.');

It's giving me this error

is_file() expects parameter 1 to be a valid path, string given
...
/home/vagrant/spark-etr/vendor/symfony/http-foundation/File/File.php:36
#1 /home/vagrant/spark-etr/vendor/symfony/http-foundation/File/File.php(36): is_file('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...')
#2 /home/vagrant/spark-etr/vendor/symfony/http-foundation/BinaryFileResponse.php(94): Symfony\\Component\\HttpFoundation\\File\\File->__construct('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...')
#3 /home/vagrant/spark-etr/vendor/symfony/http-foundation/BinaryFileResponse.php(53): Symfony\\Component\\HttpFoundation\\BinaryFileResponse->setFile('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...', 'attachment', false, true)
#4 /home/vagrant/spark-etr/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(125): Symfony\\Component\\HttpFoundation\\BinaryFileResponse->__construct('\\xFF\\xD8\\xFF\\xE0\\x00\\x10JFIF\\x00\\x01\\x01\\x00\\x00...', 200, Array, true, 'attachment')

The file is on s3 since I am checking for exists before downloading.

Update

Dumping the $file var gives me binary like this

enter image description here

Please help

Norris Oduro

Try

if( Storage::disk('s3')->exists($file_path) ) {
      $file =  Storage::disk('s3')->get($file_path);

      $headers = [
        'Content-Type' => 'your_content_type', 
        'Content-Description' => 'File Transfer',
        'Content-Disposition' => "attachment; filename={$yourFileName}",
        'filename'=> $yourFileName
     ];

    return response($file, 200, $headers);
}

Update

You can read more about downloading large files Why don't large files download easily in Laravel?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to download a file from S3 by the URL in a browser

From

Download file from AWS S3 using Python

From Dev

Download file from Amazon S3 using REST API

From Dev

Download apk file from S3 using DownloadManager

From Dev

Download private file from S3 using bash

From Dev

WebClient DownloadFile not working when download docx file with canvas from VSTS

From Dev

Unable to download file from URL using python

From Dev

Unable to download from subfolder of a bucket using AWS S3 iOS SDK

From Dev

How to download files from s3 given the file path using boto3 in python

From Dev

Download subset of file from s3 using Boto3

From

Download a file from S3 using full URI using AWS SDK for Go

From Dev

Unable to download images from AWS S3, Swift 3

From Dev

How to download a file using from s3 private bucket without AWS cli

From Dev

How do I download a JPG file from Amazon S3 into memory using Python?

From Dev

Angular how to download file from S3 Amazon using ng-click

From Dev

Download File from s3 using Boto via proxy server

From Dev

Download file from AWS S3 using fetch method throws CORS error

From Dev

How to download all the files from S3 bucket irrespective of file key using python

From Dev

How to download file from S3 into EC2 instance using packers to build custom AMI

From Dev

download an image file from S3 and send as email in python using BytesIO and MIMEApplication results to zero bytes

From Dev

How to download specific version file from s3 using transfer utility

From Dev

Is there a way to download a csv file from a website and upload it directly to Amazon S3 using Lambda?

From Dev

Download File with Specific Version-ID from AWS S3 using Python

From Dev

Net.WebClient.DownloadFile to download file of Google Drive from batch file not recognize some characters

From Dev

s3 file upload does not return response

From Dev

Unable to download files from S3 bucket

From Dev

How to download file from external api response source using Laravel?

From Dev

Unable to return response from function

From Dev

Can't implement timeout when trying to download a file using WebClient.DownloadFile() or WebRequest

Related Related

  1. 1

    Unable to download a file from S3 by the URL in a browser

  2. 2

    Download file from AWS S3 using Python

  3. 3

    Download file from Amazon S3 using REST API

  4. 4

    Download apk file from S3 using DownloadManager

  5. 5

    Download private file from S3 using bash

  6. 6

    WebClient DownloadFile not working when download docx file with canvas from VSTS

  7. 7

    Unable to download file from URL using python

  8. 8

    Unable to download from subfolder of a bucket using AWS S3 iOS SDK

  9. 9

    How to download files from s3 given the file path using boto3 in python

  10. 10

    Download subset of file from s3 using Boto3

  11. 11

    Download a file from S3 using full URI using AWS SDK for Go

  12. 12

    Unable to download images from AWS S3, Swift 3

  13. 13

    How to download a file using from s3 private bucket without AWS cli

  14. 14

    How do I download a JPG file from Amazon S3 into memory using Python?

  15. 15

    Angular how to download file from S3 Amazon using ng-click

  16. 16

    Download File from s3 using Boto via proxy server

  17. 17

    Download file from AWS S3 using fetch method throws CORS error

  18. 18

    How to download all the files from S3 bucket irrespective of file key using python

  19. 19

    How to download file from S3 into EC2 instance using packers to build custom AMI

  20. 20

    download an image file from S3 and send as email in python using BytesIO and MIMEApplication results to zero bytes

  21. 21

    How to download specific version file from s3 using transfer utility

  22. 22

    Is there a way to download a csv file from a website and upload it directly to Amazon S3 using Lambda?

  23. 23

    Download File with Specific Version-ID from AWS S3 using Python

  24. 24

    Net.WebClient.DownloadFile to download file of Google Drive from batch file not recognize some characters

  25. 25

    s3 file upload does not return response

  26. 26

    Unable to download files from S3 bucket

  27. 27

    How to download file from external api response source using Laravel?

  28. 28

    Unable to return response from function

  29. 29

    Can't implement timeout when trying to download a file using WebClient.DownloadFile() or WebRequest

HotTag

Archive