feat(#127): adding multiple file upload

- fix missing option params
This commit is contained in:
Sefa Ilkimen 2019-09-27 13:25:14 +02:00
parent ae3e821639
commit 4ace394464
4 changed files with 14 additions and 10 deletions

View File

@ -373,7 +373,7 @@ const tests = [
},
validationFunc: function (driver, result) {
result.type.should.be.equal('throwed');
result.message.should.be.equal('advanced-http: header values must be strings');
result.message.should.be.equal(require('../www/messages').TYPE_MISMATCH_HEADERS);
}
},
{
@ -384,7 +384,7 @@ const tests = [
},
validationFunc: function (driver, result) {
result.type.should.be.equal('throwed');
result.message.should.be.equal('advanced-http: header values must be strings');
result.message.should.be.equal(require('../www/messages').INVALID_HEADER_VALUE);
}
},
{

View File

@ -9,7 +9,7 @@ module.exports = function init(jsUtil, cookieHandler, messages, base64, errorCod
b64EncodeUnicode: b64EncodeUnicode,
checkClientAuthMode: checkClientAuthMode,
checkClientAuthOptions: checkClientAuthOptions,
checkFileOptions: checkFileOptions,
checkUploadFileOptions: checkUploadFileOptions,
checkFollowRedirectValue: checkFollowRedirectValue,
checkForBlacklistedHeaderKey: checkForBlacklistedHeaderKey,
checkForInvalidHeaderValue: checkForInvalidHeaderValue,
@ -217,7 +217,7 @@ module.exports = function init(jsUtil, cookieHandler, messages, base64, errorCod
return checkKeyValuePairObject(params, ['String', 'Array'], messages.TYPE_MISMATCH_PARAMS);
}
function checkFileOptions(filePaths, names) {
function checkUploadFileOptions(filePaths, names) {
var opts = {
filePaths: checkArray(filePaths, ['String'], messages.TYPE_MISMATCH_FILE_PATHS),
names: checkArray(names, ['String'], messages.TYPE_MISMATCH_NAMES)
@ -380,14 +380,18 @@ module.exports = function init(jsUtil, cookieHandler, messages, base64, errorCod
options = options || {};
return {
data: jsUtil.getTypeOf(options.data) === 'Undefined' ? null : options.data,
filePath: options.filePath || '',
filePaths: options.filePaths || [],
followRedirect: checkFollowRedirectValue(options.followRedirect || globals.followRedirect),
headers: checkHeadersObject(options.headers || {}),
method: checkHttpMethod(options.method || validHttpMethods[0]),
name: options.name || '',
names: options.names || [],
params: checkParamsObject(options.params || {}),
responseType: checkResponseType(options.responseType || validResponseTypes[0]),
serializer: checkSerializer(options.serializer || globals.serializer),
timeout: checkTimeoutValue(options.timeout || globals.timeout),
followRedirect: checkFollowRedirectValue(options.followRedirect || globals.followRedirect),
headers: checkHeadersObject(options.headers || {}),
params: checkParamsObject(options.params || {}),
data: jsUtil.getTypeOf(options.data) === 'Undefined' ? null : options.data
};
}
};

View File

@ -19,7 +19,7 @@ module.exports = {
POST_PROCESSING_FAILED: 'advanced-http: an error occured during post processing response:',
TYPE_MISMATCH_DATA: 'advanced-http: "data" option supports only following data types:',
TYPE_MISMATCH_FILE_PATHS: 'advanced-http: "filePaths" option needs to be an string array, <filePaths: string[]>',
TYPE_MISMATCH_HEADERS: 'advanced-http: "headers" option needs to be an dictionary style object, <headers: {[key: string]: string}>',
TYPE_MISMATCH_HEADERS: 'advanced-http: "headers" option needs to be an dictionary style object with string values, <headers: {[key: string]: string}>',
TYPE_MISMATCH_NAMES: 'advanced-http: "names" option needs to be an string array, <names: string[]>',
TYPE_MISMATCH_PARAMS: 'advanced-http: "params" option needs to be an dictionary style object, <params: {[key: string]: string | string[]}>',
};

View File

@ -156,7 +156,7 @@ module.exports = function init(exec, cookieHandler, urlUtil, helpers, globalConf
var data = helpers.getProcessedData(options.data, options.serializer);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', options.method, [url, data, options.serializer, headers, options.timeout, options.followRedirect, options.responseType]);
case 'upload':
var fileOptions = helpers.checkFileOptions(options.filePaths || [options.filePath], options.names || [options.name]);
var fileOptions = helpers.checkUploadFileOptions(options.filePaths || [options.filePath], options.names || [options.name]);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'uploadFile', [url, headers, fileOptions.filePaths, fileOptions.names, options.timeout, options.followRedirect, options.responseType]);
case 'download':
var onDownloadSuccess = helpers.injectCookieHandler(url, helpers.injectFileEntryHandler(success));