Skip to content

Instantly share code, notes, and snippets.

@jbinkleyj
Forked from Chris927/fileupload-experiment.html
Created September 22, 2013 10:39
Show Gist options
  • Save jbinkleyj/6658769 to your computer and use it in GitHub Desktop.
Save jbinkleyj/6658769 to your computer and use it in GitHub Desktop.
<!--
see also: https://github.com/blueimp/jQuery-File-Upload/issues/473
This didn't work with an 'old' version of the plugin, try the latest one.
Idea is to do file upload all programmatically, thus only sending files once user has confirmed what to do with the files.
-->
<div class="row">
<div class="span10">
<script type="text/javascript">
function doStuffWithFiles(files) {
console.log("do stuff, files=" + files.files);
document.myfiles = files.files; // TODO: not like this, just for now :)
var result = confirm("Confirm if you want to upload! (We'd rather ask if you want to create new versions of files or have new files or cancel)");
if (result) {
console.log("now upload...");
try {
var r = $.fn.fileupload('send',
{ files: document.myfiles,
done: function(e, data) {
console.log("done, textStatus=" + data.textStatus);
}
});
} catch (error) {
console.log("error: " + error);
}
} else {
console.log("don't upload.");
}
};
</script>
<form id="dummy_for_plugin" action="<%= node_upload_path(@folder) %>" method="post" enctype="multipart/form-data"></form>
<form>
<input id="myfiles" type="file" multiple="multiple">Select file(s)</input>
<input class="btn btn-primary" value="Do stuff with the files" type="submit"
onclick="doStuffWithFiles($('#myfiles')[0]); return false; "/>
</form>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment