diff --git a/projects/ucap-webmessenger-api/src/lib/utils/parameter.util.ts b/projects/ucap-webmessenger-api/src/lib/utils/parameter.util.ts index 96c8602e..ab29f31e 100644 --- a/projects/ucap-webmessenger-api/src/lib/utils/parameter.util.ts +++ b/projects/ucap-webmessenger-api/src/lib/utils/parameter.util.ts @@ -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; + } }