user15738027
user15738027

Reputation:

Download file in Laravel from AWS S3(non public bucket)

I am able to save all my files in the bucket but having difficulties with download.
My code is:

$url = Storage::disk('s3')->temporaryUrl(
        $request->file, now()->addMinutes(10)
    );
    return Storage::disk('s3')->download($url);

Full file path stored in $request->file

Example path: https://bucket_name.privacy_region_info/folder_inside_bucket/cTymyY2gzakfczO3j3H2TtbJX4eeRW4Uj073CZUW

I am getting the fallowing https://prnt.sc/1ip4g77

Did I not understand the purpose od generating temporaryUrl? How can I download files from S3 non public bucket?

BTW I am using Laravel 8 and league/flysystem-aws-s3-v3 1.0.29.

Upvotes: 0

Views: 1958

Answers (1)

Edd Aslin
Edd Aslin

Reputation: 294

The error message you have shown suggests your user does not have the correct permissions, or that the file does not exist.

If you are sure the file exists, i would suspect a permissions issue.

In AWS IAM, make sure the user has a policy attached to it that grants the correct permissions.

In this case from the comments, i can see the user only has "Write" permissions. You will need explicit "Read" permissions too.

Upvotes: 0

Related Questions