AWSS3TransferUtilityErrorDomain Code=2 on ios

假如想象 提交于 2020-03-23 12:16:05

问题


AWSS3TransferUtilityErrorDomain Code=2

getting this error when uploading reaches 100% on iOS while android is working fine.

I am using react-native-s3. but it seems to be an issue with sdk or my bucket policy but I don't know how to fix this.

More info: To upload, I am using CognitoCredentials, the region, IdentityPool, and sessionToken generated from our server.

EDIT: This only happens on iOS. Android is working fine.


回答1:


Typically this is an S3 bucket policy issue, permissions. Below is an example policy script for s3.

<key>AWS</key>
    <dict>
        <key>CredentialsProvider</key>
        <dict>
            <key>CognitoIdentity</key>
            <dict>
                <key>Default</key>
                <dict>
                    <key>PoolId</key>
                    <string>us-west-2:xxxxx</string>
                    <key>Region</key>
                    <string>USWest2</string>
                </dict>
            </dict>
        </dict>
        <key>S3TransferUtility</key>
        <dict>
            <key>Default</key>
            <dict>
                <key>Region</key>
                <string>**USEast1**</string>
            </dict>
        </dict>
    </dict>



回答2:


So it seems my problem was wrong region. I don't know why Android works though.




回答3:


I know this is an old question, however it's better to write my situation and solution. In my iOS (Swift) project, I was trying to upload a picture after login (using Cognito) and I got this error:

Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=2 "(null)" 

Everything seemed well on code below:

transferUtility.uploadData(
            data,
            key: "my-picture.png",
            contentType: "image/png",
            expression: expression,
            completionHandler: completionHandler).continueWith { (task) -> AnyObject? in
                if let error = task.error {
                    print("Error: \(error.localizedDescription)")
                    DispatchQueue.main.async {
                        print("Error on upload: \(error.localizedDescription)")
                    }
                }

                if let _ = task.result {
                    DispatchQueue.main.async {
                        print("Upload Starting!")
                    }
                }

                return nil;
        }

The solution is on AWS Amplify Storage documentation. As stated there, I should have written the key value like key: "private/{user_identity_id}/my-picture.png"

Maybe, it will help anybody in the future.



来源:https://stackoverflow.com/questions/42456903/awss3transferutilityerrordomain-code-2-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!