Giter Club home page Giter Club logo

Comments (11)

drowl-developer avatar drowl-developer commented on May 31, 2024 3

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.

Ashish-Nanda avatar Ashish-Nanda commented on May 31, 2024 1

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.

Ashish-Nanda avatar Ashish-Nanda commented on May 31, 2024

@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.

drowl-developer avatar drowl-developer commented on May 31, 2024

@Ashish-Nanda

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.

Ashish-Nanda avatar Ashish-Nanda commented on May 31, 2024

@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.

drowl-developer avatar drowl-developer commented on May 31, 2024

@Ashish-Nanda

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.

fjnoyp avatar fjnoyp commented on May 31, 2024

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.

drowl-developer avatar drowl-developer commented on May 31, 2024

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.

fjnoyp avatar fjnoyp commented on May 31, 2024

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.

horgag avatar horgag commented on May 31, 2024

@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.

drowl-developer avatar drowl-developer commented on May 31, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.