fix(formData): refactor formData

This commit is contained in:
Philipp Kunz 2018-07-20 00:35:23 +02:00
parent 3417f09cdb
commit 0a17591eae

View File

@ -11,25 +11,6 @@ export interface IFormField {
payload: string; payload: string;
} }
/**
* retrieve the FormData headers in reliable way
* @param formDataArg
*/
const getFormDataHeaders = (formDataArg: plugins.formData) => {
const done = plugins.smartpromise.defer();
formDataArg.getLength((err, length) => {
if (err) {
done.reject(err);
}
const headers = Object.assign(
{ "Content-Length": length },
formDataArg.getHeaders()
);
done.resolve(headers);
});
return done.promise;
};
const appendFormField = async ( const appendFormField = async (
formDataArg: plugins.formData, formDataArg: plugins.formData,
formDataField: IFormField formDataField: IFormField
@ -54,13 +35,10 @@ export const postFormData = async (
for (const formField of payloadArg) { for (const formField of payloadArg) {
await appendFormField(form, formField); await appendFormField(form, formField);
} }
const pipeLog: any = async (...args) => {
console.log(args);
};
const requestOptions = Object.assign({}, optionsArg, { const requestOptions = Object.assign({}, optionsArg, {
headers: { headers: {
...(optionsArg.headers), ...(optionsArg.headers),
...getFormDataHeaders(form) ...form.getHeaders()
}, },
requestBody: form requestBody: form
}); });