1 // © 2013 Benoît Pin MINES ParisTech
6 DDFileUploader = function(dropbox
, uploadUrl
) {
7 this.dropbox
= dropbox
;
8 this.uploadUrl
= uploadUrl
;
10 addListener(dropbox
, 'dragenter', function(evt
){self
.dragenter(evt
);});
11 addListener(dropbox
, 'dragover', function(evt
){self
.dragover(evt
);});
12 addListener(dropbox
, 'drop', function(evt
){self
.drop(evt
);});
15 DDFileUploader
.prototype.dragenter = function(evt
) {
17 disablePropagation(evt
);
20 DDFileUploader
.prototype.dragover = function(evt
) {
22 disablePropagation(evt
);
23 evt
= getEventObject(evt
);
24 var dt
= evt
.dataTransfer
;
25 dt
.dropEffect
= 'copy';
29 DDFileUploader
.prototype.drop = function(evt
) {
31 disablePropagation(evt
);
33 var dt
= evt
.dataTransfer
;
34 dt
.dropEffect
= 'copy';
35 this.handleFiles(dt
.files
);
38 DDFileUploader
.prototype.handleFiles = function(files
) {
40 for (i
= 0; i
< files
.length
; i
++) {
42 console
.log(file
.type
);
48 DDFileUploader
.prototype.upload = function(file
) {
49 var reader
= new FileReader();
50 var xhr
= new XMLHttpRequest();
53 // this.xhr.upload.addEventListener("progress", function(e) {
54 // if (e.lengthComputable) {
55 // var percentage = Math.round((e.loaded * 100) / e.total);
56 // self.ctrl.update(percentage);
60 // xhr.upload.addEventListener("load", function(e){
61 // self.ctrl.update(100);
62 // var canvas = self.ctrl.ctx.canvas;
63 // canvas.parentNode.removeChild(canvas);
66 xhr
.open("PUT", this.uploadUrl
+ '/' + file
.name
);
67 xhr
.setRequestHeader("Content-Type", file
.type
);
68 // xhr.overrideMimeType('text/plain; charset=x-user-defined-binary');
69 reader
.onload = function(evt
) {
70 xhr
.sendAsBinary(evt
.target
.result
);
72 reader
.readAsBinaryString(file
);