Skip to content

Commit 7a983de

Browse files
committed
Issue 9
1 parent 69ebe35 commit 7a983de

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

example.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
url: function() {
2121
return prompt("Url", "/");
2222
},
23-
sendBoundary: $.browser.mozilla,
23+
sendBoundary: window.FormData || $.browser.mozilla,
2424
onStart: function(event, total) {
2525
return confirm("You are trying to upload " + total + " files. Are you sure?");
2626
},
@@ -32,6 +32,9 @@
3232
},
3333
setProgress: function(val) {
3434
$("#progress_report_bar").css('width', Math.ceil(val*100)+"%");
35+
},
36+
onFinishOne: function(event, response, name, number, total) {
37+
alert(response);
3538
}
3639
});
3740
});

jquery.html5_upload.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
onError: function(event, name, error) {
1919
},
20+
onBrowserIncompatible: function() {
21+
alert("Sorry, but your browser is incompatible with uploading files using HTML5 (at least, with current preferences.\n Please install the latest version of Firefox, Safari or Chrome");
22+
},
2023
autostart: true,
2124
autoclear: true,
2225
stopOnFirstError: false,
@@ -116,7 +119,18 @@
116119
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
117120
xhr.setRequestHeader("X-File-Name", file.fileName);
118121
xhr.setRequestHeader("X-File-Size", file.fileSize);
119-
if (options.sendBoundary) {//Thanks to jm.schelcher
122+
123+
if (!options.sendBoundary) {
124+
xhr.setRequestHeader("Content-Type", "multipart/form-data");
125+
xhr.send(file);
126+
}
127+
128+
if (window.FormData) {//Many thanks to scottt.tw
129+
var f = new FormData();
130+
f.append('user_file[]', file);
131+
xhr.send(f);
132+
}
133+
else if (file.getAsBinary) {//Thanks to jm.schelcher
120134
var boundary = '------multipartformboundary' + (new Date).getTime();
121135
var dashdash = '--';
122136
var crlf = '\r\n';
@@ -154,8 +168,7 @@
154168
xhr.sendAsBinary(builder);
155169
}
156170
else {
157-
xhr.setRequestHeader("Content-Type", "multipart/form-data");
158-
xhr.send(file);
171+
options.onBrowserIncompatible();
159172
}
160173
}
161174
upload_file(0);

0 commit comments

Comments
 (0)