aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.33k stars 248 forks source link

Error when uploading video using S3 Plugin #166

Closed monish-siva closed 3 years ago

monish-siva commented 4 years ago

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"
            }
        }
    }
}
''';
fjnoyp commented 4 years ago

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.

jamesonwilliams commented 4 years ago

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

darmoz commented 4 years ago

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

monish-siva commented 4 years ago

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());
}

}

rubana28 commented 4 years ago

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 ?

offlineprogrammer commented 3 years ago

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

offlineprogrammer commented 3 years ago

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