From flutter amplify uploaded image to s3 bucket successfully but not able to set global public access for that object

0

Using flutter amplify connected to s3 bucket which is public. To connect I am using identity provider which uses cognito user pool for authentication. Also associated identity provider to IAM role which has admin access to S3. Usecase is that I have to upload an image using logged in user mobile. Once. uploaded it should become available for global user (not app users but to anyone). But when I uploaded with below options it still denying access for public to access using url. What am I missing?

    final result = await Amplify.Storage.uploadFile(
      localFile: AWSFile.fromStream(imageStream, size: imageBytes.length),
      key: keyPath,
      options: StorageUploadFileOptions(accessLevel: StorageAccessLevel.guest, metadata: {'acl': 'public-read'}),
      onProgress: (progress) {
        safePrint('Fraction completed: ${progress.fractionCompleted}');
      },
    ).result;
1개 답변
0

Thanks for your question.

It seems like you are using the Amplify Flutter library to upload a file to an S3 bucket and trying to make it publicly accessible. The code you provided specifies the access level as StorageAccessLevel.guest and sets the ACL (Access Control List) metadata to 'public-read', which should theoretically make the uploaded object publicly accessible.

To make the object publicly accessible, you need to set the ACL to "public-read" at the time of object creation or after the object is created. You can try the following code to update the ACL of the uploaded object to "public-read":

final response = await Amplify.Storage.updateObjectACL({ bucketName: '', key: '', acl: 'public-read' });

However, there are a few considerations to ensure that the object is indeed publicly accessible:

Double-check the S3 bucket policy to make sure it allows public access. You can configure a bucket policy that allows public access to objects.

Ensure that the CORS (Cross-Origin Resource Sharing) configuration of your S3 bucket allows requests from any origin (or from your app's origin).

You can take a look at the official documentation for some examples.

You can also check how to set the file access level here.

AWS
David C
답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠