lundi 1 juin 2015

AWS S3 Upload - Using AccessKey, SecretKey and SessionToken - iOS SDK

I am working on iOS Application, where i need to upload the images in to AWS S3Bucket. I have got the temporary credential(accessKey,secretKey, sessionToken and bucketName) from the server to upload the images.

I am finding it difficult to identify the correct API to use this credential to upload the images.

AWS sample program is given using AWSCognitoCredentialsProvider.

I have got the working Android version of code to upload the images in to S3. But i could not find the corresponding APIs in iOS SDK.

 BasicSessionCredentials basiccredentials = new BasicSessionCredentials(
                            MY_ACCESS_KEY_ID, MY_SECRET_KEY,
                            MY_SESSION_TOKEN);
AmazonS3Client s3Client = new AmazonS3Client(
                            basiccredentials);
TransferManager manager = new TransferManager(s3Client);
PutObjectRequest por = new PutObjectRequest(Constants.getPictureBucket(), Constants.PICTURE_NAME,file name);
 manager.upload(por);

iOS SDK has the following CredentialsProvider classes

  1. AWSCognitoCredentialsProvider
  2. AWSStaticCredentialsProvider
  3. AWSWebIdentityCredentialsProvider

AWSStaticCredentialsProvider class accepts only accessKey and secretKey. Other 2 classes expects different parameters.

When i use AWSStaticCredentialsProvider with accessKey and secretKey to upload the images, i am getting the following error message

Upload failed: [Error Domain=NSURLErrorDomain Code=-1017 "cannot parse response" UserInfo=0x7f8773f70ee0 {NSUnderlyingError=0x7f8773f4bbb0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1017.)", NSErrorFailingURLStringKey=http://ift.tt/1M3BUeo, NSErrorFailingURLKey=http://ift.tt/1M3BUeo, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-1, NSLocalizedDescription=cannot parse response}]

This error message is not clear whether the issue with the credential Provider or something else

Any help is highly appreciated to resolve this issue

Thank you




2 commentaires:

  1. Hi
    Did you get any solution for this?
    Even I am facing the same issue.

    RépondreSupprimer
  2. I had set wrong string in upload request bucket field. Setting the correct name solved my issue

    RépondreSupprimer