How to Store values to Amplify S3 Flutter?

272 views Asked by At

In my application i need to use s3 to store images and video. So i have added amplify_storage_s3, amplify_flutter packages to pubspec.yaml.

I also have a jsondata as follows

{
    "statusCode": 200,
    "message": "Aws credentials getting success",
    "data": {
        "AccessKeyId": "AKIATR",
        "SecretAccessKey": "+BCL/54/XiwXF3wM36L1+y4",
        "expiresAt": "2021-11-07T04:11:11.000Z",
        "directoryPath": "posts/images/",
        "bucket": "assets"
    }
}

In the above json i need values of AccessKey,directoryPath,bucket to be stored to the amplify s3 along with the image files. I've added a function to store the values to s3.

 Future<String?> uploadfile(file) async {
    try {
      final result = await Amplify.Storage.uploadFile(
        local: file,
        key: _mediaResponse!.accessKeyId.toString(),
        
      );
    } catch (e) {
      setErrorMessage(e.toString());
    }
  }

How can i pass the values of AccessKey,directoryPath,bucket using amplifys3 properly?

1

There are 1 answers

0
Andrija On

Typically, you would create your S3 bucket using amplify CLI, and it would configure everything for you in amplifyconfiguration.dart file - this is where your Amplify object will get the configuration.

If you want to use the existing S3 bucket (i.e. the one not created by Amplify CLI) - which is what you seam to be trying to do you can follow this: https://docs.amplify.aws/lib/storage/existing-resources/q/platform/flutter/