【发布时间】:2020-11-13 11:49:52
【问题描述】:
我正在尝试使用本机反应将图像文件和数据(对象或数组)发送到后端。我尝试使用 fetch 和下面的代码并让它将图像发送到后端。但我的目标是将图像和数据一起发送。我怎样才能做到这一点?
uploadPhoto = async (response) => {
const formData = new FormData();
formData.append('fileToUpload', {
uri: response.path,
name: 'image',
type: response.mime,
imgPath: response.path
});
const infos={ad:'onur',soyad:'cicek'};
try {
const rest = await fetch('https://www.birdpx.com/mobile/fotografyukle/'+this.state.user.Id, {
method: 'POST',
headers: { 'Accept': 'application/json', 'Content-type': 'multipart/form-data' },
body: formData
});
const gelenVeri = await rest.text();
let convertedVeri=JSON.parse(gelenVeri);
console.log(convertedVeri);
return false
} catch (err) {
console.log(err)
}
};
我需要发布const infos={ad:'onur',soyad:'cicek'}; 和图片。
【问题讨论】:
标签: javascript reactjs react-native post fetch