Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for #63 #64

Merged
merged 3 commits into from

2 participants

@wingedfox

Fixed additional params in request
Fixed upload of the multiple files for a single entity

@RubaXa RubaXa merged commit 2695c28 into mailru:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 11, 2013
  1. added filename escaping for Content-Disposition header

    Ilya Lebedev authored
  2. fixed log message

    Ilya Lebedev authored
  3. added checks for multiple files in a single request and additional re…

    Ilya Lebedev authored
    …quest params
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 8 deletions.
  1. +29 −5 lib/FileAPI.Form.js
  2. +7 −3 lib/FileAPI.XHR.js
View
34 lib/FileAPI.Form.js
@@ -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);
@@ -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 {
@@ -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;
View
10 lib/FileAPI.XHR.js
@@ -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";
@@ -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){
@@ -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);
Something went wrong with that request. Please try again.