0

I have followed some of tutorials from https://www.youtube.com/watch?v=UMgApUhg7ic to upload image to my s3 bucket.

This tutorial works perfectly fine with iOS simulator, but not working on my test iphone7. I have written some debug codes to figure out what is causing the problem, but none of it comes out.

I have searched for a while about this issue, but none of it mentioning my problem. Is there something that I am missing for my codes to work on actual device, not on simulator??

AppDelegate.swift

let AWS_Pool_ID = Bundle.main.object(forInfoDictionaryKey: "AWS_Pool_ID") as! String
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.APNortheast2, identityPoolId: AWS_Pool_ID)
let configuration = AWSServiceConfiguration(region:.APNortheast2, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration

UploadViewController.swift

let transferUtility = AWSS3TransferUtility.default()
let imageData = self.image.jpegData(compressionQuality: 1.0)
let imageName = UUID().uuidString+".jpg"
let bucketName = "hello-world-bucket-name"
let progressBlock:AWSS3TransferUtilityProgressBlock = { task,progess in
    DispatchQueue.main.async {
        progressView.progress = Float(progess.fractionCompleted)
    }
}

let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = progressBlock
transferUtility.uploadData(imageData!, bucket: bucketName, key: imageName, contentType: "image/jpeg", expression: expression, completionHandler: { task,error in
    print("transferutility works")
    if let error = error {
        print(error)
    } else {
        let imageURL = "https://\(bucketName).s3.ap-northeast-2.amazonaws.com/\(imageName)"
        self.submitData.uploads = [imageURL]
        print(URL(string:imageURL)!)
    }
})
Mahmut Acar
  • 713
  • 2
  • 7
  • 26
Shawn N
  • 17
  • 4

1 Answers1

0

This sounds like a permission-issue.

If you are logged in your aws-account on the device, you are developing your app, you are logged in as "admin" in the background. If you starting your app from a real device, which isn't connected to your iMac/MacBook, you aren't logged in on the aws-console as admin anymore. The permission by default denies the access to your bucket for anybody except admin(you).

For test purposes set the bucket permissions to public and try it again.

Chris
  • 227
  • 2
  • 16
  • I have checked bucket policy, and it is already set to public. I have checked the error log, and it states, ```Finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." ```NSErrorFailingURLStringKey=https://hello-world-bucket-name.s3-ap-northeast-2.amazonaws.com/622A9425-368F-48C8-BE31-1C0F823C9AE7.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAXXSL5AJQAZLGANZV%2F20191110%2Fap-northeast-2%2Fs3%2Faws4_request&X-Amz-Date=20191110T110135Z&X-Amz-Expires=2999&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Security-Token=IQoJbYS1ydZb1KpKP05M – Shawn N Nov 10 '19 at 14:54
  • Thanks Chris! It was a policy problem. SOLVED! – Shawn N Nov 11 '19 at 07:44