Javascript Expo Formdata无法将图像发送到api rest

Javascript Expo Formdata无法将图像发送到api rest,javascript,react-native,expo,Javascript,React Native,Expo,大家好,我正在使用expo SDK 39.0.2制作一个web前端,但我有一个大问题,实际上我没有找到解决方案,我正在尝试将类似formdata的图像发送到我的后端,但在mi后端这是空的;这不是我的api rest的问题,我从postman发送了一个类似的tequest,但都不起作用…但从formdata不起作用,我想:“这是我发送formdata的方式的问题” 这是我的代码: //组件代码 const imagepreview=async()=>{ 让结果=等待ImagePicker.lau

大家好,我正在使用expo SDK 39.0.2制作一个web前端,但我有一个大问题,实际上我没有找到解决方案,我正在尝试将类似formdata的图像发送到我的后端,但在mi后端这是空的;这不是我的api rest的问题,我从postman发送了一个类似的tequest,但都不起作用…但从formdata不起作用,我想:“这是我发送formdata的方式的问题”

这是我的代码:

//组件代码
const imagepreview=async()=>{
让结果=等待ImagePicker.launchImageLibraryAsync({
允许编辑:false,
相位:[4,3],
质量:0.6,
});
console.log(结果)
如果(result.cancelled==false){
setImage(result.uri)
让uriParts=result.uri.split('.');
让fileType=uriParts[uriParts.length-1];
settype(文件类型)
}
}
const sendData=async()=>{
//使用fetch和FormData API上载图像
让formData=等待新的formData();
//假设“photo”是服务器期望的表单字段的名称
wait formData.append('photo'{
名称:`photo.${type}`,
类型:`image/${type}`,
uri:图像,
});
const send=wait user.changeprofilepicture(formData)
最终我解决了。。 我将世博会图像选择器更改为世博会文档选择器,如下所示:

const imagepreview=async()=>{
const trye=await DocumentPicker.getdocumentsync({type:'image/*})
setFile(trye.file)
setImage(trye.uri)
console.log(trye)
}
const sendData=async()=>{
formData.append('photo',file);
console.log(文件)
返回等待获取('http://127.0.0.1:3333/api/changeprofilepicture', {
方法:“POST”,
正文:formData,
});
}