Add FormData support for http utility
This commit is contained in:
@ -10,10 +10,17 @@ const http = {
|
|||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
method: method,
|
method: method,
|
||||||
body: JSON.stringify(data),
|
|
||||||
headers,
|
headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data instanceof FormData) {
|
||||||
|
options.body = data;
|
||||||
|
delete options.headers['Accept'];
|
||||||
|
delete options.headers['Content-Type'];
|
||||||
|
} else {
|
||||||
|
options.body = JSON.stringify(data);
|
||||||
|
}
|
||||||
|
|
||||||
if (method === 'GET') {
|
if (method === 'GET') {
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
|
@ -99,10 +99,7 @@ export default {
|
|||||||
|
|
||||||
console.log(this.uploadUrl, 'this.uploadUrl')
|
console.log(this.uploadUrl, 'this.uploadUrl')
|
||||||
|
|
||||||
fetch(this.uploadUrl, {
|
http.post(this.uploadUrl, formData)
|
||||||
method: 'POST',
|
|
||||||
body: formData,
|
|
||||||
})
|
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
console.log(json)
|
console.log(json)
|
||||||
|
@ -108,10 +108,7 @@ export default {
|
|||||||
formData.append('keterangan', form.keterangan.value);
|
formData.append('keterangan', form.keterangan.value);
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
||||||
fetch(this.uploadUrl, {
|
http.post(this.uploadUrl, formData)
|
||||||
method: 'POST',
|
|
||||||
body: formData,
|
|
||||||
})
|
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
console.log(json)
|
console.log(json)
|
||||||
|
Reference in New Issue
Block a user