首先说下这个问题很坑,append的Js的object类型无效,我们后台用的是java
上错不成功的代码
let url = 'http://192.168.1.120:8090/app/release';
let params = {parentId: "0", text: this.state.textContent, postType: , profitType: }
let formdata = new FormData();
formdata.append('file', {uri: this.state.envURL[].uri, type: 'image/jpg', name: 'image.jpg'});
formdata.append('appUserPost', String(params));
fetch(url, {
method: 'post',
headers: {
'Content-Type': 'multipart/form-data; boundary=6ff46e0b6b5148d984f148b6542e5a5d',
body: formdata
}).then(response => {
console.log("image uploaded")
}).catch(err => {
console.log(err)
正确的是拆分object
成功的代码
let url = 'http://192.168.0.89:8080/app/release';
var appUserPost = { 'appUserPost': params, type: 'application/octet-stream' }
var file = { uri: this.state.envURL, type: 'multipart/form-data', name: 'image.png' }
let formdata = new FormData();
formdata.append('file', file); // you can append anyone.
formdata.append('parentId', "0")
formdata.append('text', "asdfasd")
formdata.append('postType', )
formdata.append('profitType', )
console.log("formdata", JSON.stringify(formdata))
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
// 'Content-Type': 'multipart/form-data',
processData: false,
contentType: false,
body: formdata
}).then(function (response) {
console.log(response)
}).catch(err => {
console.log(err)
版权声明:本文为CSDN博主「u011135887」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011135887/article/details/78600621