android - react-native 使用emu成功发送图像表单数据,但在真实设备上出现错误422
问题描述
所以这是我的问题:我的代码在从真实设备发送数据时只返回错误 422,但在模拟器上做得很好是我的表单数据代码:
const data = new FormData();
data.append('approval_store_code', this.state.selectedApotik.store_code);
data.append('delivery_method_id', 1);
data.append('recipe_document_images[]', {
name: 'recipePhotos1',
type: 'image/jpeg',
uri:
Platform.OS === 'android'
? this.state.imageResep[0].uri
: this.state.imageResep[0].uri.replace('file://', ''),
});
这是我发送到服务器时的代码
this.setState({spinner: true});
const response = await REQ.createRecipe(this.state.accessToken, data);
console.log(response);
if (response.status == 200) {
console.log(response);
this.setState({spinner: false});
this.props.navigation.navigate('SuccessFormPharmacy');
} else {
alert('error');
this.setState({spinner: false});
}
} catch (error) {
this.setState({spinner: false});
console.log('error send data : ', error);
alert('error send Data!');
return null;
}
axios 代码:
return axios({
method: 'POST',
url: `${API.BASE_URL}/v1/pharmacy/order`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${accessToken}`,
},
body: formData,
});
奇怪的是,我尝试使用 fetch 而不是 axios,不适用于真实设备,但在模拟器上做得很好我尝试先将图像保存到设备,它保存但没有成功发送到服务器
在真实设备上返回错误 422
解决方案
推荐阅读
- react-native - 按钮单击时未定义不是对象(评估“_this.props.navigation.navigate”)
- c# - 如何使用 C# 将过滤后的数据从 Autodesk Revit 导出到 MS-Access?
- javascript - 循环到嵌套数组并修改数据
- node.js - 加密后无法解密数据
- c++ - select中的最大FD值是多少?
- laravel - 如果给定值不为零,Laravel 存在验证
- ms-access - 您可以为 ms-access 中的字段分配一系列数字吗?
- php - WordPress,查询未找到相关帖子
- android - R8 仍然在堆栈跟踪中,即使它在属性中被关闭
- ios - 如何在 Swift 中以编程方式访问系统颜色?