Skip to content

Instantly share code, notes, and snippets.

@dongyuwei
Last active August 29, 2015 13:56
Show Gist options
  • Save dongyuwei/9170781 to your computer and use it in GitHub Desktop.
Save dongyuwei/9170781 to your computer and use it in GitHub Desktop.
<form action="http://up.qiniu.com/" enctype="multipart/form-data" class="dropzone dz-clickable" id="upload-form">
<div class="dz-default dz-message">
<span>Drop files here to upload</span>
</div>
<input name="token" type="hidden" value="<%= @token %>">
<input name="x:uid" type="hidden" value="<%= current_user.id %>">
<div class="fallback">
<input name="file" type="file" multiple />
</div>
</form>
<script>
Dropzone.autoDiscover = false;
$(function() {
var dropzone = new Dropzone("#upload-form");
var images = [];
dropzone.on("success", function(file, responseData) {
// console.log(responseData.key, responseData.hash, responseData['x:uid']);
responseData.image_name = file.name;
images.push(responseData);
}).on("complete", function(file) {
if (this.getQueuedFiles().length == 0 && this.getUploadingFiles().length == 0) {
// console.log("complete",images);
$.ajax({
type: "POST",
url: '/store_file_hash.json',
data: {
'images' : images
},
success: function(data){
location.href = data.location;
},
dataType: 'json'
});
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment