in www/browser/FileTransfer.js [146:208]
reader.onloadend = function () {
const blob = new Blob([this.result], { type: mimeType });
// Prepare form data to send to server
const fd = new FormData();
fd.append(fileKey, blob, fileName);
for (const prop in params) {
if (Object.prototype.hasOwnProperty.call(params, prop)) {
fd.append(prop, params[prop]);
}
}
xhr.open(httpMethod, server);
// Fill XHR headers
for (const header in headers) {
if (Object.prototype.hasOwnProperty.call(headers, header)) {
xhr.setRequestHeader(header, headers[header]);
}
}
xhr.onload = function () {
// 2xx codes are valid
if (this.status >= 200 && this.status < 300) {
const result = new FileUploadResult();
result.bytesSent = blob.size;
result.responseCode = this.status;
result.response = this.response;
delete transfers[that._id];
successCallback(result);
} else if (this.status === 404) {
fail(FileTransferError.INVALID_URL_ERR, this.status, this.response);
} else {
fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
}
};
xhr.ontimeout = function () {
fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
};
xhr.onerror = function () {
fail(FileTransferError.CONNECTION_ERR, this.status, this.response);
};
xhr.onabort = function () {
fail(FileTransferError.ABORT_ERR, this.status, this.response);
};
xhr.upload.onprogress = function (e) {
if (that.onprogress) {
that.onprogress(e);
}
};
xhr.send(fd);
// Special case when transfer already aborted, but XHR isn't sent.
// In this case XHR won't fire an abort event, so we need to check if transfers record
// isn't deleted by filetransfer.abort and if so, call XHR's abort method again
if (!transfers[that._id]) {
xhr.abort();
}
};