Skip to content

Commit e48a95b

Browse files
committed
+ dev 1.2.5
2 parents 8a313cc + 46822e8 commit e48a95b

File tree

8 files changed

+243
-145
lines changed

8 files changed

+243
-145
lines changed

FileAPI.min.js

Lines changed: 66 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ All the other codes - fatal error, user's involvement is recommend.
529529
header('Access-Control-Allow-Methods: POST, OPTIONS');
530530
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Range, Content-Disposition, Content-Type'); // and other custom headers
531531
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); // a comma-separated list of domains
532+
header('Access-Control-Allow-Credentials: true');
532533

533534
if( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ){
534535
exit;
@@ -670,9 +671,25 @@ All the other codes - fatal error, user's involvement is recommend.
670671
671672
672673
## Changelog
674+
* [#91](https://github.com/mailru/FileAPI/issues/91): replace `new Image` to `FileAPI.newImage`
675+
* + FileAPI.withCredentials: true
676+
* [#90](https://github.com/mailru/FileAPI/issues/90): Fixed `progress` event
677+
678+
679+
### 1.2.5
680+
* [#86](https://github.com/mailru/FileAPI/issues/86): Smarter upload recovery
681+
* [#87](https://github.com/mailru/FileAPI/issues/87): Fixed upload files into browsers that do not support FormData
682+
* Fixed support "accept" attribute for Flash.
683+
* Fixed detection of HTML5 support for FireFox 3.6
684+
* + FileAPI.html5 option, default "true"
685+
686+
673687
### 1.2.4
674688
* Fixed auto orientation image by EXIF (Flash)
675689
* Fixed image dimensions after rotate (Flash)
690+
* [#82](https://github.com/mailru/FileAPI/issues/82): "undefined" data-fields cause exceptions
691+
* [#83](https://github.com/mailru/FileAPI/issues/83): Allow requests without files
692+
* [#84](https://github.com/mailru/FileAPI/pull/84): Fixed connection abort when waiting for connection recovery
676693
677694
678695
### 1.2.3

crossdomain.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<allow-access-from domain="*.rubaxa.org" secure="false"/>
1010
<allow-access-from domain="github.com" secure="false"/>
1111
<allow-access-from domain="*.github.com" secure="false"/>
12+
<allow-access-from domain="github.io" secure="false"/>
13+
<allow-access-from domain="*.github.io" secure="false"/>
1214
<allow-access-from domain="mail.ru" secure="false"/>
1315
<allow-access-from domain="*.mail.ru" secure="false"/>
1416
<allow-access-from domain="imgsmail.ru" secure="false"/>

index.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515

1616
if( strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' ){
17-
header('HTTP/1.1 201 Created');
18-
1917
$files = FileAPI::getFiles();
2018
$images = array();
2119
fetchImages($files, $images);
@@ -265,6 +263,7 @@ function onFiles(files){
265263
data: {
266264
num: 10
267265
, str: "foo"
266+
, 'undefined': void 0
268267
},
269268
files: {
270269
photos: FileAPI.filter(files, function (file){ return /^image/.test(file.type) })
@@ -336,12 +335,14 @@ function onFiles(files){
336335
}
337336

338337
FileAPI.each(result.images, function (dataURL, name){
339-
$('<div/>')
340-
.append('<div><b>'+name+'</b></div>')
341-
.append($(new Image).attr('src', dataURL))
342-
.css({ margin: 5, border: '1px dotted #666', padding: 5 })
343-
.appendTo('body')
344-
;
338+
FileAPI.newImage(dataURL, function (err, img){
339+
$('<div/>')
340+
.append('<div><b>'+name+'</b></div>')
341+
.append(img)
342+
.css({ margin: 5, border: '1px dotted #666', padding: 5 })
343+
.appendTo('body')
344+
;
345+
});
345346
});
346347

347348
document.getElementById('Log').innerHTML += '<pre style="font-size: 11px;">'+xhr.responseText.substr(0, 200)+'</pre>';

lib/FileAPI.Flash.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
})();
2424

2525

26-
if( 1 && api.support.flash && (api.onlyFlash || !api.support.html5 || api.cors && !api.support.cors) ) (function (){
26+
if( 1 && api.support.flash && (0 || !api.html5 || !api.support.html5 || api.cors && !api.support.cors) ) (function (){
2727
var
2828
_attr = api.uid()
2929
, _retry = 0
@@ -237,7 +237,7 @@
237237
accept.push( ext );
238238
});
239239

240-
flash.cmd(evt, 'accept', accept.length ? '.'+accept.join(',.') : '*');
240+
flash.cmd(evt, 'accept', accept.length ? accept.join(',')+','+accept.join(',').toUpperCase() : '*');
241241
}
242242
},
243243

@@ -402,12 +402,7 @@
402402
}, base64, fn);
403403
}
404404
else {
405-
var img = new Image;
406-
api.event.one(img, 'error abort load', function (evt){
407-
fn(evt.type != 'load' && evt.type, img);
408-
img = null;
409-
});
410-
img.src = 'data:'+ file.type +';base64,'+ base64;
405+
api.newImage('data:'+ file.type +';base64,'+ base64, fn);
411406
}
412407
})
413408
});
@@ -486,7 +481,11 @@
486481
}
487482
});
488483

489-
api.log('flash.XHR._send:', flashId, fileId, files);
484+
if( !(fileId || flashId) ){
485+
return this.parent.apply(this, arguments);
486+
} else {
487+
api.log('flash.XHR._send:', flashId, fileId, files);
488+
}
490489

491490
_this.xhr = {
492491
headers: {},
@@ -691,12 +690,9 @@
691690

692691

693692
// Check dataURI support
694-
var dataURICheck = new Image;
695-
api.event.one(dataURICheck, 'error load', function (){
696-
api.support.dataURI = !(dataURICheck.width != 1 || dataURICheck.height != 1);
697-
dataURICheck = null;
693+
api.newImage('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==', function (err, img){
694+
api.support.dataURI = !(img.width != 1 || img.height != 1);
698695
flash.init();
699696
});
700-
dataURICheck.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
701697
})();
702698
})(FileAPI, window, document);

lib/FileAPI.Form.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
append: function (name, blob, file, type){
1414
this.items.push({
1515
name: name
16-
, blob: blob && blob.blob || blob
17-
, file: file || blob.name
18-
, type: type || blob.type
16+
, blob: blob && blob.blob || (blob == void 0 ? '' : blob)
17+
, file: blob && (file || blob.name)
18+
, type: blob && (type || blob.type)
1919
});
2020
},
2121

@@ -35,7 +35,7 @@
3535
api.log('FileAPI.Form.toHtmlData');
3636
this.toHtmlData(fn);
3737
}
38-
else if( this.multipart ){
38+
else if( this.multipart || !FormData ){
3939
api.log('FileAPI.Form.toMultipartData');
4040
this.toMultipartData(fn);
4141
}
@@ -113,7 +113,7 @@
113113
data.params.push(encodeURIComponent(file.name) + "=" + encodeURIComponent(file.blob));
114114
}
115115
data.start = -1;
116-
data.end = -1;
116+
data.end = data.file.FileAPIReadPosition || -1;
117117
data.retry = 0;
118118
});
119119
},
@@ -143,13 +143,33 @@
143143

144144
toMultipartData: function (fn){
145145
this._to([], fn, function (file, data, queue, boundary){
146-
data.push(
147-
'--_' + boundary + ('\r\nContent-Disposition: form-data; name="'+ file.name +'"'+ (file.file ? '; filename="'+ encode(file.file) +'"' : '')
148-
+ (file.file ? '\r\nContent-Type: '+ (file.type || 'application/octet-stream') : '')
149-
+ '\r\n'
150-
+ '\r\n'+ (file.file ? file.blob : encode(file.blob))
151-
+ '\r\n')
152-
);
146+
var
147+
isFile = !!file.file
148+
, blob = file.blob
149+
, done = function (blob){
150+
data.push(
151+
'--_' + boundary + ('\r\nContent-Disposition: form-data; name="'+ file.name +'"'+ (isFile ? '; filename="'+ encode(file.file) +'"' : '')
152+
+ (isFile ? '\r\nContent-Type: '+ (file.type || 'application/octet-stream') : '')
153+
+ '\r\n'
154+
+ '\r\n'+ (isFile ? blob : encode(blob))
155+
+ '\r\n')
156+
);
157+
queue.next();
158+
}
159+
;
160+
161+
queue.inc();
162+
163+
if( api.isFile(blob) ){
164+
api.readAsBinaryString(blob, function (evt/**Object*/){
165+
if( evt.type == 'load' ){
166+
done(evt.result);
167+
}
168+
});
169+
}
170+
else {
171+
done(blob);
172+
}
153173
}, api.expando);
154174
}
155175
};

lib/FileAPI.XHR.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
},
7171

7272
_send: function (options, data){
73+
7374
var _this = this, xhr, uid = _this.uid, url = options.url;
7475

7576
api.log('XHR._send:', data);
@@ -128,14 +129,21 @@
128129
}
129130
else {
130131
// html5
132+
if (this.xhr && this.xhr.aborted) {
133+
api.log("Error: already aborted");
134+
return;
135+
}
131136
xhr = _this.xhr = api.getXHR();
132137

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

137142
xhr.open('POST', url, true);
138-
xhr.withCredential = "true";
143+
144+
if( api.withCredentials ){
145+
xhr.withCredentials = "true";
146+
}
139147

140148
if( !options.headers || !options.headers['X-Requested-With'] ){
141149
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
@@ -189,10 +197,10 @@
189197
options.pause(data.file, options);
190198

191199
// smart restart if server reports about the last known byte
192-
var lkb = xhr.getResponseHeader('X-Last-Known-Byte');
200+
var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10);
193201
api.log("X-Last-Known-Byte: " + lkb);
194202
if (lkb) {
195-
data.end = parseInt(lkb);
203+
data.end = lkb;
196204
} else {
197205
data.end = data.start - 1;
198206
}
@@ -213,6 +221,15 @@
213221
_this.end(xhr.status);
214222
} else {
215223
// next chunk
224+
225+
// shift position if server reports about the last known byte
226+
var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10);
227+
api.log("X-Last-Known-Byte: " + lkb);
228+
if (lkb) {
229+
data.end = lkb;
230+
}
231+
data.file.FileAPIReadPosition = data.end;
232+
216233
setTimeout(function () {
217234
_this._send(options, data);
218235
}, 0);
@@ -223,7 +240,7 @@
223240
};
224241

225242
data.start = data.end + 1;
226-
data.end = Math.min(data.start + options.chunkSize, data.size ) - 1;
243+
data.end = Math.max(Math.min(data.start + options.chunkSize, data.size ) - 1, data.start);
227244

228245
var slice;
229246
(slice = 'slice') in data.file || (slice = 'mozSlice') in data.file || (slice = 'webkitSlice') in data.file;

0 commit comments

Comments
 (0)