in www/FileTransfer.js [88:160]
FileTransfer.prototype.upload = function (filePath, server, successCallback, errorCallback, options, trustAllHosts) {
argscheck.checkArgs('ssFFO*', 'FileTransfer.upload', arguments);
// check for options
let fileKey = null;
let fileName = null;
let mimeType = null;
let params = null;
let chunkedMode = true;
let headers = null;
let httpMethod = null;
const basicAuthHeader = getBasicAuthHeader(server);
if (basicAuthHeader) {
server = server.replace(getUrlCredentials(server) + '@', '');
options = options || {};
options.headers = options.headers || {};
options.headers[basicAuthHeader.name] = basicAuthHeader.value;
}
if (options) {
fileKey = options.fileKey;
fileName = options.fileName;
mimeType = options.mimeType;
headers = options.headers;
httpMethod = options.httpMethod || 'POST';
if (httpMethod.toUpperCase() === 'PUT') {
httpMethod = 'PUT';
} else {
httpMethod = 'POST';
}
if (options.chunkedMode !== null || typeof options.chunkedMode !== 'undefined') {
chunkedMode = options.chunkedMode;
}
if (options.params) {
params = options.params;
} else {
params = {};
}
}
const fail =
errorCallback &&
function (e) {
const error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body, e.exception);
errorCallback(error);
};
const self = this;
const win = function (result) {
if (typeof result.lengthComputable !== 'undefined') {
if (self.onprogress) {
self.onprogress(newProgressEvent(result));
}
} else {
if (successCallback) {
successCallback(result);
}
}
};
exec(win, fail, 'FileTransfer', 'upload', [
filePath,
server,
fileKey,
fileName,
mimeType,
params,
trustAllHosts,
chunkedMode,
headers,
this._id,
httpMethod
]);
};