swiftamazon-s3awss3transferutility

transferUtility.uploadData works perfectly fine with iOS simulator, but not working while testing on actual device iOS13


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)!)
    }
})

Solution

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