<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>