HTML5 Drag n Drop File Upload
Posted
by
Paris
on Stack Overflow
See other posts from Stack Overflow
or by Paris
Published on 2011-06-28T21:17:50Z
Indexed on
2011/06/29
8:22 UTC
Read the original article
Hit count: 278
I'm running a website, where I'd like yo upload files with Drag 'n Drop, using HTML5's File Api and FileReader API. I have successfully managed to create a new FileReader
, but I don't know how to upload the file. My code (javascript) is the following :
holder = document.getElementById('uploader');
holder.ondragover = function () {
$("#uploader").addClass('dragover');
return false;
};
holder.ondragend = function () {
$("#uploader").removeClass('dragover');
return false;
};
holder.ondrop = function (e) {
$("#uploader").removeClass('dragover');
e.preventDefault();
var file = e.dataTransfer.files[0],
reader = new FileReader();
reader.onload = function (event) {
//I shoud upload the file now...
};
reader.readAsDataURL(file);
return false;
};
I also have a form (id : upload-form) and an input file field (id : upload-input). Do you have any ideas?
P.S. I use jQuery, that's why there is $("#uploader") and others..
© Stack Overflow or respective owner