Created
May 9, 2014 11:30
-
-
Save sgimeno/afe93250887d77b297ca to your computer and use it in GitHub Desktop.
Script to upload image files to Amazon S3. Uses jQuery promise API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
"Content-Type": "image/jpeg" | |
}; | |
ft.upload(imageURI, s3URI, | |
function (e) { | |
deferred.resolve(e); | |
}, | |
function (e) { | |
deferred.reject(e); | |
}, options); | |
return deferred.promise(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment