}
}
- xhr.onload = function(evt) {
-
- if (xhr.status === 200) {
- uploads[id] && delete uploads[id];
- successCallback({
- bytesSent: file.size,
- responseCode: xhr.status,
- response: xhr.response
- });
- } else if (xhr.status === 404) {
- fail(FileTransferError.INVALID_URL_ERR, this.status, this.response);
- } else {
- fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
- }
- };
-
xhr.ontimeout = function(evt) {
fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
};
}
// sending already initialized request
+ // 'onload' needs to be defined here because it needs blobFile.size
+ xhr.onload = function(evt) {
+ // 2xx codes are valid
+ if (xhr.status >= 200 && xhr.status < 300) {
+ uploads[id] && delete uploads[id];
+ successCallback({
+ bytesSent: blobFile.size,
+ responseCode: xhr.status,
+ response: xhr.response
+ });
+ } else if (xhr.status === 404) {
+ fail(FileTransferError.INVALID_URL_ERR, this.status, this.response);
+ } else {
+ fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
+ }
+ };
xhr.send(fd);
// Special case when transfer already aborted, but XHR isn't sent.