Uploading content to AWS3 error on Xcode 13

121 views Asked by At

Error uploading file: Optional("The operation couldn’t be completed. (com.amazonaws.AWSS3TransferUtilityErrorDomain error 4.)")

Some errors that are related to this error commonly are the PoolID and bucket not in same region. or mismatch in iOS versions.

I have checked that my identityPoolID and bucket are of same region. my bucket is also set to public

my Macos ver is 12.1 hence in my Podfile I included: platform :ios, '12.1'

Gist of my code:

let bucketName = "bucketpublic"
var completionHandler: AWSS3TransferUtilityUploadCompletionHandlerBlock?
let link1 = URL(fileURLWithPath:"/Users/hello/Desktop/pink.jpeg")

func uploadjsonfile(Url: URL, type: String){   //1
            
            let key = "rkey"
        
            let expression  = AWSS3TransferUtilityUploadExpression()
            expression.progressBlock = { (task: AWSS3TransferUtilityTask,progress: Progress) -> Void in
              print(progress.fractionCompleted)   //2
              if progress.isFinished{           //3
                print("Upload Finished...")
                
              }
            }
            
            expression.setValue("public-read-write", forRequestHeader: "x-amz-acl")   //4
            expression.setValue("public-read-write", forRequestParameter: "x-amz-acl")

            completionHandler = { (task:AWSS3TransferUtilityUploadTask, error:NSError?) -> Void in
                if(error != nil){
                    print("Failure uploading file")
                    
                }else{
                    print("Success uploading file")
                }
            } as? AWSS3TransferUtilityUploadCompletionHandlerBlock
            
            
            //5
            AWSS3TransferUtility.default().uploadFile(Url, bucket: bucketName, key: String(key), contentType: type, expression: expression, completionHandler: self.completionHandler).continueWith(block: { (task:AWSTask) -> AnyObject? in
                if(task.error != nil){
                    print("Error uploading file: \(String(describing: task.error?.localizedDescription))")
                }
                if(task.result != nil){
                    print("Starting upload...")}
      
                return nil
            })
        }
0

There are 0 answers