Comments (11)
Thanks, @Ashish-Nanda, and @fjnoyp. I figured it out our bucket policy doesn't have a prefix(public/protected/private) previously. I added them and it worked.
from amplify-flutter.
Thats great @shravyamachanna!
The error messages implied there was something missing in the policies configured manually as compared to how the Amplify CLI sets them up. Glad that you were able to figure it out!
Will go ahead and close out the issue now that it's resolved.
from amplify-flutter.
@shravyamachanna
Did you set up your backend with the CLI? Could you share your amplifyconfiguration.dart
file.
Also Have you enabled access for guest users?
If not you may need to log in before uploading.
from amplify-flutter.
I used existing AWS resources. I haven't used CLI to set it up.
Our use case is to make authenticated users upload to a bucket with their identityId.. as it isn't working either. I have tried the Cognito auth user who is logged In to upload images to the public bucket.
amplifyconfiguration.dart :
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-west-2"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "*******",
"AppClientId": "******",
"AppClientSecret": "*****",
"Region": "us-west-2"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH"
}
},
"S3TransferUtility": {
"Default": {
"Bucket": "****",
"Region": "us-west-2"
}
}
}
}
},
"analytics": {
"plugins": {
"awsPinpointAnalyticsPlugin": {
"pinpointAnalytics": {
"appId": "******",
"region": "us-east-1"
},
"pinpointTargeting": {
"region": "us-east-1"
}
}
}
},
"storage": {
"plugins": {
"awsS3StoragePlugin": {
"bucket": "******",
"region": "us-west-2"
}
}
}
}''';
from amplify-flutter.
@shravyamachanna, the terminology public
can be confusing sometimes. I suspect you have a public
folder in the bucket but the bucket is not truly public
allowing anyone to upload/read from it as that would not be a good practice from a security standpoint, and we recommend you scope down the permissions.
Since you have set up your Cognito resources manually and not using the CLI, looking at the authorization related errors, I think it could be that you are missing the IAM roles and permissions necessary for users to Put/Get/List/Delete objects in the bucket.
I suggest you take a look at our docs here to get an idea about the roles and policies you would need to create.
Hopefully this will address your issue!
from amplify-flutter.
Previously I used to upload using the same credentials on iOS and Android and it used to work fine(IAM roles are exactly the same now). I used to use flutter platform channel to call AWS SDK for iOS and Android. Now I'm migrating to flutter Amplify.
Bucket properties haven't changed as it is still working fine when I upload it using iOS or Android AWS SDK.
As far as the public goes ...I created a temporary bucket to test ...We won't use that bucket as its not a best practice.
Please help me resolve the issue.
from amplify-flutter.
Hi @shravyamachanna thanks for providing those extra details.
Strange how native iOS and Android was working for you before. Can you provide the Android storage upload code you used? Also, can you provide the amplifyConfiguration file for Android native, perhaps we can compare the differences between that and the one used in your flutter project.
from amplify-flutter.
Hi @fjnoyp,
Thank you for looking into the issue. Below are the awsconfiguration.json and android code which we are using with flutter platform channels.
awsconfiguration.json
{
"UserAgent": "aws-amplify/cli",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "******",
"Region": "us-west-2"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "********",
"AppClientId": "********",
"AppClientSecret": "********",
"Region": "us-west-2"
}
},
"S3TransferUtility": {
"Default": {
"Region": "us-west-2"
}
}
}
Android storage upload code
filePath = call.argument("filePath");
key = call.argument("key");
String idId = AWSMobileClient.getInstance().getIdentityId() + "/" +key;
File file = new File(filePath);
new AwsHelper(MainActivity.this, new AwsHelper.OnUploadCompleteListener() {
@Override
public void onUploadComplete() {
runOnUiThread(() -> {
Map<String, Object> hMap = new HashMap<>();
hMap.put(STATUS, true);
hMap.put(TAG, "Upload Successful");
hMap.put(MESSAGE, idId);
result.success(hMap);
});
}
@Override
public void onFailed() {
runOnUiThread(() -> {
result.error("Upload Error", "Failed to upload", null);
});
}
}, idId).uploadImage(file);
from amplify-flutter.
Hi @shravyamachanna
I thought you were using Amplify Android Storage (https://docs.amplify.aws/lib/storage/upload/q/platform/android) via the method channel before. I'm not too sure what AWSHelper is.
I've been looking through your dart code and it looks correct - it appears you are using the code in the sample app which should be good.
Based on the information you've provided it's looking like your backend resources are not configured correctly as your dart code seems correct. In this case I would recommend following the advice that Ashish provided before: https://docs.amplify.aws/lib/storage/getting-started/q/platform/js#manual-setup-import-storage-bucket
Using the Amplify CLI is the best way to automatically get this all set up without having to worry about configuring these things manually.
from amplify-flutter.
@shravyamachanna could you expand a bit more on your solution. I have the same problem... Is it something I have to do with the configuration file?
from amplify-flutter.
@horgag ... Our issue was with the bucket policy, previously our bucket policy didn't allow uploads to the buckets with the prefix(public/protected/private). After allowing the object to be uploaded with prefix in bucket policy, it worked.
Hope this helps.
from amplify-flutter.
Related Issues (20)
- Listen to Amplify.Hub events within Authenticator? HOT 3
- S3 access denied when making the API call HOT 15
- [amplify_secure_storage] Missing Apple Privacy Manifest HOT 3
- [Feature Request] Webassembly (Wasm) support in Amplify Flutter HOT 3
- [Feature Request] Support ampx --output-version 1 HOT 3
- Analytics record event is throwing SqliteException HOT 6
- Bump drift version to ^2.18.0 HOT 5
- AWSHttpRequest body creation fails on web HOT 1
- DataStore subscription not working with contains HOT 3
- Auth.signInWithWebUI with AuthProvider.custom redirect URI issue HOT 9
- Datastore error handler has unparsable error message HOT 1
- Model parsing fails for complex non-model types HOT 2
- [Datastore errorhandler] Incorporate a variable in error object to obtain the initial request. HOT 1
- web app, import amplify_storage_s3.dart cause drift-2.14.1/lib/src/web/wasm_setup/shared.dart The argument type 'LegacySyncFileHandle' can't be assigned to the parameter type 'Object' because 'LegacySyncFileHandle' is nullable and 'Object' isn't. HOT 5
- Pinpoint Notifications always use APNs Sandbox channel HOT 11
- Login with email is slow HOT 18
- Amplify Fails to Configure - WorkerBeeExceptionImpl HOT 5
- AmplifyAPI modelProvider not working moving from v1 to v2 HOT 2
- NotAuthorizedServiceException when answering NEW_PASSWORD_REQUIRED challenge HOT 7
- Amplify.Hub.listen never get "ready" HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amplify-flutter.