简体   繁体   中英

How to Store values to Amplify S3 Flutter?

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?

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 (ie 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM