amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

Error when uploading video using S3 Plugin

Open monish-siva opened this issue 6 years ago • 7 comments

I setup amplify on my flutter project using the guides, but when I try to upload a video onto S3 from my Samsung Galaxy s9 I get this error message:

I/FilePickerUtils(32033): File loaded and cached at:/data/user/0/com.example.dotsmobile_homepage/cache/file_picker/Screen_Recording_20201024-184238_Instagram.mp4
I/FilePickerDelegate(32033): Absolute file path:/data/user/0/com.example.dotsmobile_homepage/cache/file_picker/Screen_Recording_20201024-184238_Instagram.mp4
I/flutter (32033): PlatformException(AmplifyException, UPLOAD_FILE_OPERATION_FAILED, {PLATFORM_EXCEPTIONS: {platform: Android, localizedErrorMessage: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference, recoverySuggestion: }})

Here is my amplifyconfig file (I have taken out the keys and PoolID):

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "",
                        "AppClientId": "",
                        "AppClientSecret": "",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "",
                        "Region": "us-east-1"
                    }
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsS3StoragePlugin": {
                "bucket": "",
                "region": "us-east-1",
                "defaultAccessLevel": "guest"
            }
        }
    }
}
''';

monish-siva avatar Oct 29 '20 16:10 monish-siva

Hi @monishkumar-sivakumar can you provide the code you use to configure Amplify and to upload the video? Did you use Amplify CLI to setup your project?

Our example app has a working file upload function as well (here). I'm wondering if you would get the same error running that project as well.

fjnoyp avatar Oct 30 '20 20:10 fjnoyp

Duplicated of https://github.com/aws-amplify/amplify-flutter/issues/169, which has been formatted.

jamesonwilliams avatar Oct 30 '20 21:10 jamesonwilliams

I have experinced same issue with image uploader Code:

  void _upload() async {
    try {
      print('In upload');
      File local = await getImageFileFromAssets(images.first);
      local.existsSync();
      print('Path: '+local.path);
      final key = 'key';
      Map<String, String> metadata = <String, String>{};
      metadata['category'] = 'category';
      metadata['desc'] = 'A photo';
      S3UploadFileOptions options = S3UploadFileOptions(
          accessLevel: StorageAccessLevel.guest, metadata: metadata);
      UploadFileResult result = await Amplify.Storage.uploadFile(
          key: key, local: local, options: options);
      setState(() {
        _uploadFileResult = result.key;
      });
    } catch (e) {
      print('UploadFile Err: ' + e.toString());
    }
  }

and amplify config:

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "id",
                            "Region": "eu-west-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "id",
                        "AppClientId": "id",
                        "AppClientSecret": "secret",
                        "Region": "eu-west-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "bucketname",
                        "Region": "eu-west-1"
                    }
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsS3StoragePlugin": {
                "bucket": "bucket name",
                "region": "eu-west-1",
                "defaultAccessLevel": "guest"
            }
        }
    }
}''';

I am receiving exactly same error message as @monishkumar-sivakumar

darmoz avatar Nov 02 '20 21:11 darmoz

Hi @fjnoyp I used the amplify cli to configure amplify. here my code:

void configureAmplify() async { // First add plugins (Amplify native requirements) AmplifyStorageS3 storage = new AmplifyStorageS3(); AmplifyAuthCognito auth = new AmplifyAuthCognito(); amplify.addPlugin(authPlugins: [auth], storagePlugins: [storage]);

// Configure
await amplify.configure(amplifyconfig);

setState(() {
  _isAmplifyConfigured = true;
});

}

void _upload() async { File local = await FilePicker.getFile(type: FileType.video); local.existsSync(); final key = new DateTime.now().toString(); Map<String, String> metadata = <String, String>{}; metadata['name'] = 'filename'; metadata['desc'] = 'A test file'; S3UploadFileOptions options = S3UploadFileOptions( accessLevel: StorageAccessLevel.guest, metadata: metadata);

try {
  UploadFileResult result = await Amplify.Storage.uploadFile(
      key: key, local: local, options: options);
  setState(() {
    _uploadFileResult = result.key;
  });
} catch (e) {
  print(e.toString());
}

}

monish-siva avatar Nov 04 '20 21:11 monish-siva

I have experinced same issue with image uploader Code:

  void _upload() async {
    try {
      print('In upload');
      File local = await getImageFileFromAssets(images.first);
      local.existsSync();
      print('Path: '+local.path);
      final key = 'key';
      Map<String, String> metadata = <String, String>{};
      metadata['category'] = 'category';
      metadata['desc'] = 'A photo';
      S3UploadFileOptions options = S3UploadFileOptions(
          accessLevel: StorageAccessLevel.guest, metadata: metadata);
      UploadFileResult result = await Amplify.Storage.uploadFile(
          key: key, local: local, options: options);
      setState(() {
        _uploadFileResult = result.key;
      });
    } catch (e) {
      print('UploadFile Err: ' + e.toString());
    }
  }

and amplify config:

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "id",
                            "Region": "eu-west-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "id",
                        "AppClientId": "id",
                        "AppClientSecret": "secret",
                        "Region": "eu-west-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "bucketname",
                        "Region": "eu-west-1"
                    }
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsS3StoragePlugin": {
                "bucket": "bucket name",
                "region": "eu-west-1",
                "defaultAccessLevel": "guest"
            }
        }
    }
}''';

I am receiving exactly same error message as @monishkumar-sivakumar

File local = await getImageFileFromAssets(images.first); here for using getImageFileFromAssets(images.first) this, do i have to use any package or anything ?

rubana28 avatar Nov 16 '20 17:11 rubana28

Hey @rubana28 & @monishkumar-sivakumar

Sorry for the late reply.

I tested on iOS, and Android and I couldn't reproduce the issue

Please check our example app (here) for a working file upload function

Feel free to test using the latest build and let us know if you got any issues

Thanks Mo

mo-malaka avatar May 03 '21 23:05 mo-malaka

Hey @rubana28 & @monishkumar-sivakumar

I am closing this issue for now as I didn't hear from you and I couldn't reproduce as per my comment above. We can reopen it if you are still facing the issue and when you provide details

Regards Mo

mo-malaka avatar May 21 '21 16:05 mo-malaka