amazon-archives / aws-sdk-react-native

AWS SDK for React Native (developer preview)
Apache License 2.0
631 stars 68 forks source link

Transfer Utility Code=2 "(null)" - iOS #22

Closed fabriciovergara closed 5 years ago

fabriciovergara commented 7 years ago

Hi,

I'm trying to upload a picture to a S3 bucket on iOS, but on every first upload after app start the following error is returned in the completation handler. Then the next picture doesn't even start the upload (no info cames from progress callback)

"Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=2 "(null)" UserInfo={Server=AmazonS3, Transfer-Encoding=Identity, Connection=close, Content-Type=application/xml, Date=Tue, 08 Nov 2016 16:38:58 GMT, x-amz-request-id=A33BCEA53A29008B, x-amz-id-2=ew77OTuf2kBDt7ZKbZISzQLSex7oCU/ecKMgTFasY6+F2qtqjM4lKaZkEbQtXr36ncPU4IBdfKg=}"

Env: OSX El Capitan, XCode 8.1 Device: iPhone 6s Plus iOS 10

samahyousif commented 7 years ago

I'm facing the same issue aws 4.2.1

ondrejhanak commented 7 years ago

I was getting the same error output when device time was set into the future (in iOS SDK, but still).

dccper-reuben commented 7 years ago

You could try logging out the calls made by the SDK using AWSLogger.default().logLevel = AWSLogLevel.verbose in AppDelegate.

When the image is being uploaded check if the region is being applied in the host eg: bucketname.s3..amazonaws.com

I faced an issue where the region was not being applied. So to resolve it has to set the AWSServiceConfigurations specific to region where the bucket is and then register it with the AWSS3TransferUtility and call it with the registered key.

From the AWS S3 SDK AWSS3TransferUtility: /** Creates a service client with the given service configuration and registers it for the key.

 For example, set the default service configuration in `- application:didFinishLaunchingWithOptions:`

 *Swift*

     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
         let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
         let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
         AWSS3TransferUtility.register(with: configuration!, forKey: "USWest2S3TransferUtility")

         return true
     }

 *Objective-C*

     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
         AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                                                         identityPoolId:@"YourIdentityPoolId"];
         AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
                                                                              credentialsProvider:credentialsProvider];

         [AWSS3TransferUtility registerS3TransferUtilityWithConfiguration:configuration forKey:@"USWest2S3TransferUtility"];

         return YES;
     }

 Then call the following to get the service client:

 *Swift*

     let S3TransferUtility = AWSS3TransferUtility(forKey: "USWest2S3TransferUtility")

 *Objective-C*

     AWSS3TransferUtility *S3TransferUtility = [AWSS3TransferUtility S3TransferUtilityForKey:@"USWest2S3TransferUtility"];

 @warning After calling this method, do not modify the configuration object. It may cause unspecified behaviors.

 @param configuration A service configuration object.
 @param key           A string to identify the service client.
 */
ningxia commented 6 years ago

@dccper-reuben For my case, registering the AWSS3TranserUtility solved the problem. You saved my day!!!

EdYao commented 5 years ago

@ondrejhanak Did you solve the 'time' issue? because we cannot ask users to set time accurately.

ondrejhanak commented 5 years ago

@EdYao it was only on my testing device, where date was 1 whole day off from previous testing of different feature. So users were not involved in my case.