Commit 99943685 authored by Guangshuo Chen's avatar Guangshuo Chen Committed by ddcat1115

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
parent 9c4e9c1b
...@@ -48,12 +48,21 @@ export default function request(url, options) { ...@@ -48,12 +48,21 @@ export default function request(url, options) {
}; };
const newOptions = { ...defaultOptions, ...options }; const newOptions = { ...defaultOptions, ...options };
if (newOptions.method === 'POST' || newOptions.method === 'PUT') { if (newOptions.method === 'POST' || newOptions.method === 'PUT') {
newOptions.headers = { if (!(newOptions.body instanceof FormData)) {
Accept: 'application/json', newOptions.headers = {
'Content-Type': 'application/json; charset=utf-8', Accept: 'application/json',
...newOptions.headers, 'Content-Type': 'application/json; charset=utf-8',
}; ...newOptions.headers,
newOptions.body = JSON.stringify(newOptions.body); };
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) return fetch(url, newOptions)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment