From 999436853318ec43471d5edda3f24fce760d330c Mon Sep 17 00:00:00 2001 From: Guangshuo Chen Date: Mon, 5 Feb 2018 07:52:50 +0100 Subject: [PATCH] let request.js be able to deal with FormData (#884) * let request.js be able to deal with FormData * Update request.js * Update request.js * Update request.js * Update request.js --- src/utils/request.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index 4113cc21..9b58189a 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -48,12 +48,21 @@ export default function request(url, options) { }; const newOptions = { ...defaultOptions, ...options }; if (newOptions.method === 'POST' || newOptions.method === 'PUT') { - newOptions.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json; charset=utf-8', - ...newOptions.headers, - }; - newOptions.body = JSON.stringify(newOptions.body); + if (!(newOptions.body instanceof FormData)) { + newOptions.headers = { + Accept: 'application/json', + 'Content-Type': 'application/json; charset=utf-8', + ...newOptions.headers, + }; + newOptions.body = JSON.stringify(newOptions.body); + } else { + // newOptions.body is FormData + newOptions.headers = { + Accept: 'application/json', + 'Content-Type': 'multipart/form-data', + ...newOptions.headers, + }; + } } return fetch(url, newOptions) -- GitLab