zeus-dev's avatar

Problem with getting Amazon S3 download path

Hello everyone, hope everyone is doing great.

So I guess the title of my subject resumes the problem :P.

I have a bucket in Amazon S3, it's operationnal now, I try to upload files, that's perfect !.

Now I want to retieve the uploaded file and download it, easy right ? :/.

I actually retrieve the file(cuz the name of the file is stored in the DB).

So I found the file using :

$myFile = Storage::disk("filesystems.default")->get($fileName);

public function download($file){ $headers = [ 'Content-Type' => $contentType, 'Content-Description' => 'File Transfer', 'Content-Disposition' => "attachment; filename={$file}", 'filename'=> $file ]; return response()->download(Storage::disk("filesystems.default")->get($file), $file); }

And my function

download($file) is called in a blade like {{url('/download/'. $myItem->filleName) }}

But the link generated isn't the link of my amazon S3 source, but the link of the app.

So I tried another way :

$s3=Storage::disk("s3"); $s3->getDriver()->getAdapter()->getClient()->getObjectUrl("mybucketName", $fileName);

This time the url is an amazon link, but kind of inversed :

https://{{myBucket}}.s3.{{myRegion}}.amazonaws.com/files/plxXTbB5jpzvNnN7HwxE4RRlqoMm1QK57ORXkpnW.zip

But actually the link generated in the Amazon Console is like this :

https://s3.{{regionName}}.amazonaws.com/{{myBucket}}/files/plxXTbB5jpzvNnN7HwxE4RRlqoMm1QK57ORXkpnW.zip

So anyone can help me getting a link to download my files from Amazon S3 bucket please.

thanks (:

0 likes
3 replies

Please or to participate in this conversation.