I want non-authorized download from an S3 bucket. I’ve enabled all options for public access and ACL. After a adjusting the settings, I finally no longer got the access denied error. However, now I can’t find any files. All the data I’ve uploaded, I did through the AWS web.
Bucket Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<the bucket>/*"
}
]}
Now I have a new problem. I can’t find the files, I get this error:
NoSuchKey
The specified key does not exist.public//100/gif1.gif (Service: Amazon S3; Status Code: 404; Error Code: 404 Not Found; Request ID: ***’),
Here’s the code:
Future<void> downloadFromS3(String key) async {
try {
final localPath = await getApplicationDocumentsDirectory();
final filePath = '$localPath/$key';
final result = await Amplify.Storage.downloadFile(
key: "/100/$key",
local: File(filePath),
);
} catch (e) {
print('Error downloading file [$key] : $e');
}
}
Then I run:
await configureAmplify();
await downloadFromS3('gif1.gif');
My bucket is structured like this: myBucket/100/gif1.gif.
I’ve been stuck on this for awhile now, the only thing I can assume is the problem is that in the error code you can see a public prefix “public//100/gif1.gif”. Which I don’t have, I’ve tried creating a folder “public” like this myBucket/public/folder100/file. However, that didn’t really work either.
What’s wrong?