react native无法在服务器端获取附加数据



我想将图像上传到数据库。但是,当我将fetch方法与"Content-Type"一起使用时:"multipart/form-data",但我无法在服务器端获得附加的数据。这表明我体内没有任何数据。

下面是提取部分编码

editProfile = () => {
let bodyData = new FormData();
let photo={
uri:this.state.uri,
type:this.state.type,
fileName:this.state.fileName,
}
bodyData.append('transactionCode', 'UPDATEPROFILE');
// bodyData.append('photo', photo);
console.log(bodyData);
fetch(URL, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
},
body: bodyData,
}).then((response) => response.json())
.then((responseJson) => {
alert(responseJson);
})
.catch((error) => {
alert(error);
});
}

这是我如何在服务器端检查数据的例子

const custfunction = function (req, res) {
console.log(req.body);
}

当我console.log(req(时,它显示主体:{}为空

好吧,我刚刚发现问题。我需要使用Multer来处理后端的多部分/表单数据。非常感谢。

https://www.npmjs.com/package/multer

最新更新