encodeFormData is added

This commit is contained in:
병준 박 2019-11-05 13:39:28 +09:00
parent 1f1baf74b0
commit a4ee7cc83e

View File

@ -14,14 +14,50 @@ export class ParameterUtil {
if (!param.hasOwnProperty(key)) {
return;
}
if (!!param[key]) {
parameter[parameterMap[key]] = param[key];
}
let v: any;
if (!!extraParam && !!extraParam[key]) {
parameter[parameterMap[key]] = extraParam[key];
v = extraParam[key];
} else if (!!param[key]) {
v = param[key];
}
if (!!v) {
parameter[parameterMap[key]] = v;
}
});
return 0 === Object.keys(parameter).length ? null : parameter;
}
public static encodeFormData(
parameterMap: {},
param: {},
extraParam?: {}
): FormData {
const formData: FormData = new FormData();
Object.keys(parameterMap).map(key => {
if (!param.hasOwnProperty(key)) {
return;
}
let v: any;
if (!!extraParam && !!extraParam[key]) {
v = extraParam[key];
} else if (!!param[key]) {
v = param[key];
}
if (!!v) {
if (v instanceof File) {
formData.append(parameterMap[key], v, v.name);
} else {
formData.append(parameterMap[key], v);
}
}
});
return formData;
}
}