Download S3 file links in Laravel

Nitish Kumar

I'm trying to build a small application in VueJs as frontend and Laravel as backend where I'm uploading files in my admin section to my aws-s3 while uploading the files I'm storing the link of that file in database. Every action is maintained by api calls, now I want to give option of these downloads to my end users so I'm making an axios call something like this:

downloadPDF(docs){
    const documents = {
        document: docs
    }
    axios.post('api/documents-download', documents, {headers: getHeader()}).then(response => {
        if(response.status === 200)
        {
            console.log('Downloaded')
        }
    })
},

And in my controller I'm having something like this:

public function download(Request $request)
{
    $headers = [
        'Content-Type' => 'application/pdf',
        'Content-Description' => 'File Transfer',
        'Content-Disposition' => "attachment; filename=filename.pdf",
    ];

    return response()->download($request->document, 'filename.pdf', $headers);
}

But it is throwing me error:

The file "https://s3-us-west-2.amazonaws.com/noetic-dev/2_Project/shiven-affordable-housing-surat/3_Document/Form+1/Form1.pdf" does not exist

This file clearly exists and made public as you can see above url shows the documents as linked.

Help me out with this. Thanks

Salman Zafar

i remember implementing this is in my project.. let me share a sample code with you... Laravel already provides details about s3Storage in documentation

Code:

use Illuminate\Support\Facades\Response as Download;

public function download_config(Config $config)
    {
        $headers = [
            'Content-Type'        => 'Content-Type: application/zip',
            'Content-Disposition' => 'attachment; filename="'. $config->name .'"',
        ];

        return Download::make(Storage::disk('s3')->get($config->path), Response::HTTP_OK, $headers);
    }

i'm supposing that you may be storing $config->path (path of file) this in your db. To learn more you can visit this

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Download file from cloud disk (S3) with Laravel 5.1

From Dev

Laravel - S3 multiple file zip and download

From Dev

How to scrape download links inside each folder on S3

From Dev

how to use Amazon S3 Uri links to download image?

From Dev

AWS download file to s3 on a schedule

From Dev

Does not download a file by magnet links

From Dev

Boto3 : Download file from S3

From Dev

Download S3 File Using Boto3

From Dev

Amazon S3 Download Image File by PUBLIC URL

From Dev

How to push a file saved to S3 to the frontend for download?

From Dev

Download s3 file only if upload completed

From Dev

Python: how to download a file from an S3 bucket

From Dev

How to download media file from S3 bucket in Django

From Dev

Python get s3 file from download link

From Dev

How to generate URL to download file from S3 bucket

From Dev

Download Inventory File from AWS S3

From Java

How to download GZip file from S3?

From Java

AWS S3 Java SDK - Download file help

From Javascript

Javascript to download a file from amazon s3 bucket?

From Dev

Triggering download of S3 file with presigned_url

From Dev

Download file from Amazon S3 through Carrierwave and Fog

From Dev

Download S3 file to docker image in EBS

From Dev

Amazon s3 file download from android

From

Download S3 file with a different filename than the bucket key

From

Go - Download S3 file under a prefix

From Dev

Amazon S3 client could not download file with spaces or hash?

From Dev

Python - Download file from AWS S3 for the current date

From

Download file from AWS S3 using Python

From Dev

Download file from Amazon S3 using REST API