Skip to content

Instantly share code, notes, and snippets.

@devgeeks
Created November 27, 2012 19:47
Show Gist options
  • Save devgeeks/4156546 to your computer and use it in GitHub Desktop.
Save devgeeks/4156546 to your computer and use it in GitHub Desktop.
S3 direct upload
var options = new FileUploadOptions();
options.fileKey="fileupload";
var time = new Date().getTime();
var userId = getUserId(); // In my case, Parse.User.current().id;
var fileName = userId+"-"+time+".jpg";
options.fileName = fileName;
options.mimeType ="image/jpeg";
options.chunkedMode = false;
var uri = encodeURI("https://BUCKET_NAME.s3.amazonaws.com/");
var policyDoc = "POLICY_DOC_GOES_HERE";
var signature = "SIGNATURE_GOES_HERE";
var params = {
"key": "uploads/"+fileName,
"AWSAccessKeyId": "ACCESS_KEY_GOES_HERE",
"acl": "public-read",
"policy": policyDoc,
"signature": signature,
"Content-Type": "image/jpeg"
};
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, uri, uploadSuccess, uploadFail, options);
@jowls
Copy link

jowls commented Apr 6, 2013

Thank you, this was extremely helpful to me. Although I needed to change

options.fileKey="fileupload";

to

options.fileKey="file";

The S3 server was otherwise giving me http status 400. S3 logs indicated

"POST / HTTP/1.1" 400 MaxPostPreDataLengthExceeded

@droizman
Copy link

droizman commented Jun 5, 2013

Just getting into this space and trying to find out how to generate the signature and a policy doc. Can you recommend a method?

@devgeeks
Copy link
Author

@droizman : I just used the Ruby example from http://aws.amazon.com/articles/1434

@Rajeshbiz4
Copy link

Hi I want to upload and image on s3 using ionic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment