Can't upload files to s3 with Flutter amplify

Viewed 447

Whenever I try to upload an image to my s3 bucket created in flutter nothing happens.

    final pickedFile = await picker.getImage(source: ImageSource.gallery);
    try{
    setState(() {
      if (pickedFile != null) {
        _image = File(pickedFile.path);
        
        
      } else {
        print('No image selected.');
      }
    });
    print("here");
    final key = new DateTime.now().toString();
    print(key);
    Map<String, String> metadata = <String, String>{};
metadata['name'] = 'filename';
metadata['desc'] = 'A test file';
S3UploadFileOptions options = S3UploadFileOptions(accessLevel: StorageAccessLevel.private, metadata: metadata);
try {
  UploadFileResult result = await Amplify.Storage.uploadFile(
    key: key,
    local: _image,
    options: options
  );
  print("Uploaded");
} on StorageException catch (e) {
  print(e.message);
}
}catch (e){
      Alert(
          context: context,
          type: AlertType.error,
          desc: "Error Uploading File: " + e.toString());
    }

  }

I I've found this discussion on the topic https://github.com/aws-amplify/amplify-android/discussions/550 however I don't have a amplifyconfiguration.json file I have it in .dart form. Also all of my information is present. I'm not sure why I'm not able to upload to s3. Thank you in advance!

1 Answers
final pickedFile =
    await ImagePicker().getImage(source: ImageSource.gallery);

if (pickedFile != null) {
  var imagePath = pickedFile.path;
  var nameWithExtension = imagePath.split('/')[6];
  var imageName = nameWithExtension.split('.')[0];
}

use imagePath in local
Related