amazon web services - Put file on S3 with AWS SDK 2 & Cognito for unauth users using iOS SDK 2 -
i want upload file 1 of s3 buckets.
in app have:
in app delegate
let credentialprovider = awscognitocredentialsprovider(regiontype: .useast1, identitypoolid: "us-east-1:05da3124-9aab-abd9-081231a31") let configuration = awsserviceconfiguration(region: .useast1, credentialsprovider: credentialprovider) awsservicemanager.defaultservicemanager().defaultserviceconfiguration = configuration
an upload function
func uploadfile(fileurl: nsurl, type: mediatype) { var uploadrequest = awss3transfermanageruploadrequest() uploadrequest.body = fileurl uploadrequest.key = fileurl.lastpathcomponent uploadrequest.bucket = "xxx.xxx.dev" transfermanager.upload(uploadrequest).continuewithblock { (task) -> anyobject! in if let error = task.error { log.debug("upload failed error: \(error)") } else { log.debug("object \(uploadrequest.key) uploaded \(task.result)") xxxrestmanager.sharedinstance.doregisterupload(uploadrequest.key, type: type) } return nil } }
a policy attached unauthenticated role in identity pool:
{ "version": "2012-10-17", "statement": [ { "effect": "allow", "action": [ "s3: putobject" ], "resource": "arn:aws:s3:::xxx.xxx.dev" }, { "effect": "allow", "action": [ "sns:createplatformendpoint", "sns:subscribe" ], "resource": [ "*" ] } ] }
the connection cognito correct (i have 1 unauthenticated user in aws console.
however still permission denied when try upload file. did missed?
awss3transfermanageruploadrequest
might need more permissions putobject work. have tried giving broader permissions s3 on policy? needs @ least getobject, try first "action": "s3:*"
can make sure problem in part.
Comments
Post a Comment