ios - Swift upload to s3 bucket does not end -
i'm trying upload image bucket. connection made, upload apparently starts not progress. permissions on server consider correct, because android app able upload. in appdelegate have this:
let credentialsprovider = awscognitocredentialsprovider(regiontype: awsregiontype.useast1, identitypoolid: "us-east-1:xxxxxx-xxxx-xxxx-xxxx-xxxx”, unauthrolearn: "arn:aws:iam::xxxxx:role/cognito_mybucketunauth_role", authrolearn: "arn:aws:iam::xxxxx:role/cognito_mybucketauth_role", identityprovidermanager: nil) let configuration = awsserviceconfiguration(region: awsregiontype.useast1, credentialsprovider: credentialsprovider) awsservicemanager.defaultservicemanager().defaultserviceconfiguration = configuration and image , upload
func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : anyobject]){ //getting details of image let uploadfileurl = info[uiimagepickercontrollerreferenceurl] as! nsurl let imagename = uploadfileurl.lastpathcomponent let documentdirectory = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true).first! string // getting local path let localpath = (documentdirectory nsstring).stringbyappendingpathcomponent(imagename!) //getting actual image let image = info[uiimagepickercontrolleroriginalimage] as! uiimage let data = uiimagepngrepresentation(image) data!.writetofile(localpath, atomically: true) let imagedata = nsdata(contentsoffile: localpath)! imageurl = nsurl(fileurlwithpath: localpath) campoimagem.image = image picker.dismissviewcontrolleranimated(true, completion: nil) uploadimage() } func uploadimage(){ //defining bucket , upload file name let s3bucketname: string = “mybucket" let s3uploadkeyname: string = "profile/testimage.jpg" let expression = awss3transferutilityuploadexpression() /*expression.uploadprogress = {(task: awss3transferutilitytask, bytessent: int64, totalbytessent: int64, totalbytesexpectedtosend: int64) in dispatch_async(dispatch_get_main_queue(), { let progress = float(totalbytessent) / float(totalbytesexpectedtosend) print("progress is: \(progress)") }) }*/ self.uploadcompletionhandler = { (task, error) -> void in dispatch_async(dispatch_get_main_queue(), { if ((error) != nil){ print("failed error") print("error: \(error!)"); } else{ print("sucess") } }) } let transferutility = awss3transferutility.defaults3transferutility() transferutility.uploadfile(imageurl, bucket: s3bucketname, key: s3uploadkeyname, contenttype: "image/jpeg", expression: expression, completionhander: uploadcompletionhandler).continuewithblock { (task) -> anyobject! in if let error = task.error { print("error: \(error.localizeddescription)") } if let exception = task.exception { print("exception: \(exception.description)") } if let _ = task.result { print("upload starting!") } return nil; } } print: upload starting!
i suspect it's when id , permission complete upload aws, think if upload not start, correct? how can solve this?
please check code can check adding credentials in demo project
Comments
Post a Comment