Cordova/Phonegap upload image to amazon S3 through javascript -
please me on one. can't seem find problem is. looks goes way (fetching image, policy, signature etc.) until uploads file. rejected amazon... idea why? here's upload code:
policy_json = { "expiration": "2020-08-06t12:00:00.000z", "conditions": [ {"bucket": "gloportalmobile"}, {"acl": "public-read"} ] }; var policyencbase64 = btoa(json.stringify(policy_json)); var secret = "--my--secret--key--here--"; var encodedsignature = b64_hmac_sha1(secret, policyencbase64); b64_hmac_sha1(secret, policyencbase64); var s3uri = encodeuri("https://gloportalmobile.s3.amazonaws.com/"), policybase64 = policyencbase64, signature = encodedsignature, awskey = 'my--aws--key--here--', acl = "public-read"; function upload(imageuri, filename) { var deferred = $.deferred(), ft = new filetransfer(), options = new fileuploadoptions(); options.filekey = "file"; options.filename = filename; options.mimetype = "image/jpeg"; options.chunkedmode = false; options.params = { "key": filename, "awsaccesskeyid": awskey, "acl": acl, "policy": policybase64, "signature": signature }; alert('encodedpolicy: '+policybase64); alert('encodedsignature: '+signature); alert('imageuri '+imageuri); alert('s3uri '+s3uri); ft.upload(imageuri, s3uri, function (e) { alert('cool'); deferred.resolve(e); }, function (e) { alert('rejected'); deferred.reject(e); }, options); return deferred.promise(); } return { upload: upload }
so in alert messages can see policy,signature,imageuri , s3uri values still throwing alert "rejected" message.
is because policy or signature encoded wrong? or need setup on gloportal bucket in amazon s3 accept it? or way amazon can tell me why reject it?
thanks!
i think should options.headers instead of options.params
Comments
Post a Comment