Eduardo Ribeiro
Eduardo Ribeiro

Reputation: 11

Download a file from S3 - Laravel 5.7

Im trying to download files from amazon s3, and the code here works for files like docx, pdf etc... But for images, it just open a new tab, and shows the image there, no download started.

function downloadLink($docpath)
{
    $s3 = \Storage::disk('s3');

    return $s3->url($docpath);
}

I replaced the url method with download, but that dont work at all, it says err 404 page not found.

Best regards

Upvotes: 1

Views: 1206

Answers (1)

pwagner
pwagner

Reputation: 1244

The browser behaves that way by default, but you can force it to start a download by adding the following HTTP headers in the response from the server:

Content-Type: application/octet-stream
Content-Disposition: attachement; filename="example.png"

Upvotes: 1

Related Questions