Permalink
Browse files

Support for FormData an suggested solution for other browsers

Signed-off-by: Janez Troha <janez.troha@gmail.com>
  • Loading branch information...
1 parent 8fdc28c commit d58e7c0166fc2c685022dd8d28f29d4eef479cea Janez troha committed Oct 3, 2010
Showing with 19 additions and 8 deletions.
  1. +19 −8 jquery.dnd-file-upload.js
View
@@ -118,13 +118,24 @@
upload.addEventListener("load", load, false);
xhr.open(opts.method, opts.url);
- xhr.setRequestHeader("Cache-Control", "no-cache");
- xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
- xhr.setRequestHeader("X-File-Name", file.fileName);
- xhr.setRequestHeader("X-File-Size", file.fileSize);
- xhr.setRequestHeader("Content-Type", "multipart/form-data");
- xhr.send(file);
-
+ //Use native function(Chrome 5+ ,Safari 5+ and Firefox 4+), for dealing with multipart/form-data and boundray generation
+ if(FormData){
+ var formdata = new FormData(); //see https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects
+ //'file' can be any string which you would like to associte with uploaded file even for example file.type eg:
+ //formdata.append(file.type, file);
+ //formdata.append(file.fileName, file);
+ formdata.append('file', file);
+ xhr.send(file);
+ }
+ else{
+ //TODO: Multipart boundary generation for other browsers, see http://demos.hacks.mozilla.org/openweb/imageUploader/js/extends/xhr.js
+ xhr.setRequestHeader("Cache-Control", "no-cache");
+ xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
+ xhr.setRequestHeader("X-File-Name", file.fileName);
+ xhr.setRequestHeader("X-File-Size", file.fileSize);
+ xhr.setRequestHeader("Content-Type", "multipart/form-data");
+ xhr.send(file);
+ }
$.fn.dropzone.uploadStarted(i, file);
}
}
@@ -173,4 +184,4 @@
uploadFiles(files);
}
-})(jQuery);
+})(jQuery);

0 comments on commit d58e7c0

Please sign in to comment.