Skip to content

Instantly share code, notes, and snippets.

@ivansifrim
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ivansifrim/22faebb250bc009beb0a to your computer and use it in GitHub Desktop.
Save ivansifrim/22faebb250bc009beb0a to your computer and use it in GitHub Desktop.
scope
$(function() {
function blah(data){
var ohyeah = fd;
console.log("got here");
console.log(ohyeah);
return ohyeah;
}
function getFormData(){
jQuery.ajax({
type:'GET',
url: 'http://localhost:3000/s3signature.json',
error: function(){
console.log('error!');
},
success: function(data){
console.log(data);
var res = data;
blah(data);
}
// end success
})
};
console.log("I want the data printed here: ");
console.log(getFormData());
$('#select-file').fileupload({
maxFileSize: 100000000,
fileInput: $(this),
url: 'https://ivancoffeetime.s3.amazonaws.com/',
type: 'POST',
autoUpload: true,
formData: getFormData(),
paramName: 'file', // S3 does not like nested name fields i.e. name="user[avatar_url]"
dataType: 'XML', // S3 returns XML if success_action_status is set to 201
replaceFileInput: false,
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$("#progress-bar").css('width', progress + '%')
console.log($("#progress-bar").css('width'));
},
start: function (e) {
$("#progress-bar").css('background', 'green');
$("#progress-bar").css('display', 'block');
$("#progress-bar").css('width', '0%');
$("#progress-bar").text('Loading file...');
},
done: function(e, data) {
$("#progress-bar").text("Uploading done");
// extract key and generate URL from response
var key = $(data.jqXHR.responseXML).find("Key").text();
var url = 'https://ivancoffeetime.s3.amazonaws.com/' + key;
console.log("THIS IS THE URL: " + url);
$("#thumbnail").html('<img src="'+url+'" style="width:100px;">');
},
fail: function(e, data) {
// submitButton.prop('disabled', false);
console.log(data);
$("#progress-bar").
css("background", "red").
text("Failed");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment