Skip to content

Instantly share code, notes, and snippets.

@sgimeno
Created May 9, 2014 11:30
Show Gist options
  • Save sgimeno/afe93250887d77b297ca to your computer and use it in GitHub Desktop.
Save sgimeno/afe93250887d77b297ca to your computer and use it in GitHub Desktop.
Script to upload image files to Amazon S3. Uses jQuery promise API.
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