Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #63 #64

Merged
merged 3 commits into from
Feb 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions lib/FileAPI.Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
},

toData: function (fn, options){
// allow chunked transfer if we have only one file to send
// flag is used below and in XHR._send
options._chunked = api.support.chunked && options.chunkSize > 0 && api.filter(this.items, function (item){ return item.file; }).length == 1;

if( !api.support.html5 ){
api.log('FileAPI.Form.toHtmlData');
this.toHtmlData(fn);
Expand All @@ -35,8 +39,8 @@
api.log('FileAPI.Form.toMultipartData');
this.toMultipartData(fn);
}
else if( api.support.chunked && options.chunkSize > 0 ){
api.log('FileAPI.Form.toMultipartData');
else if( options._chunked ){
api.log('FileAPI.Form.toPlainData');
this.toPlainData(fn);
}
else {
Expand Down Expand Up @@ -83,9 +87,29 @@
if( file.file ){
data.type = file.file;
}
data.name = file.blob.name;
data.file = file.blob;
data.size = file.blob.size;
if( file.blob.toBlob ){
// canvas
queue.inc();
file.blob.toBlob(function (blob){
data.name = file.name;
data.file = blob;
data.size = blob.length;
queue.next();
}, 'image/png');
}
else if( file.file ){
//file
data.name = file.blob.name;
data.file = file.blob;
data.size = file.blob.size;
}
else {
// additional data
if (!data.params) {
data.params = [];
}
data.params.push(encodeURIComponent(file.name) + "=" + encodeURIComponent(file.blob));
}
data.start = 0;
data.end = 0;
data.retry = 0;
Expand Down
10 changes: 7 additions & 3 deletions lib/FileAPI.XHR.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
// html5
xhr = _this.xhr = api.getXHR();

if (data.params) {
url += (url.indexOf('?') < 0 ? "?" : "&") + data.params.join("&");
}

xhr.open('POST', url, true);
xhr.withCredential = "true";

Expand All @@ -141,8 +145,8 @@
});


if (api.support.chunked && options.chunkSize > 0) {
// resumable upload
if ( options._chunked ) {
// chunked upload
if( xhr.upload ){
// https://github.com/blueimp/jQuery-File-Upload/wiki/Fixing-Safari-hanging-on-very-high-speed-connections-%281Gbps%29
xhr.upload.addEventListener('progress', api.throttle(function (/**Event*/evt){
Expand Down Expand Up @@ -199,7 +203,7 @@
(slice = 'slice') in data.file || (slice = 'mozSlice') in data.file || (slice = 'webkitSlice') in data.file;

xhr.setRequestHeader("Content-Range", "bytes " + data.start + "-" + data.end + "/" + data.size);
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + data.name);
xhr.setRequestHeader("Content-Disposition", 'attachment; filename=' + encodeURIComponent(data.name));

slice = data.file[slice](data.start, data.end + 1);

Expand Down