React native 如何在拍照后立即将照片传送到x-www-form-urlencoded
我想拍张照片,保存到相册中,然后马上发送图像。 (不要从相册中选择。) 拍摄当前照片、将其保存在相册中并检查uri没有问题 但是x-www-form-urlencoded发送过程无法正常工作 我认为发送API的格式可能有问题。 邮递员也附呈。(邮递员没问题。)React native 如何在拍照后立即将照片传送到x-www-form-urlencoded,react-native,expo,image-uploading,react-native-camera,x-www-form-urlencoded,React Native,Expo,Image Uploading,React Native Camera,X Www Form Urlencoded,我想拍张照片,保存到相册中,然后马上发送图像。 (不要从相册中选择。) 拍摄当前照片、将其保存在相册中并检查uri没有问题 但是x-www-form-urlencoded发送过程无法正常工作 我认为发送API的格式可能有问题。 邮递员也附呈。(邮递员没问题。) 当附加到FormData实例时,第一个参数是字段名(服务器将获取此文件的对象键),第二个参数是以下形式的对象: { uri: // The uri you received from the camera, type: // T
当附加到
FormData
实例时,第一个参数是字段名(服务器将获取此文件的对象键),第二个参数是以下形式的对象:
{
uri: // The uri you received from the camera,
type: // The file type (i.e.: image/png),
name: // The file name
}
在您的情况下,它将是这样的:
// Split the uri by `.` (periods)
const uriParts = uri.split('.');
// Grab the file type at the end of the uri
const fileType = uriParts[uriParts.length - 1];
file.append('picture', {
uri,
type: `image/${fileType}`,
name: 'FILE-NAME.${fileType}`
});
此外,发送文件时,您的
内容类型
标题应为多部分/表单数据
@bongjuri1551请与我的建议分享您的代码。var file=new FormData();consturiparts=uri.split('.');const fileType=uriParts[uriParts.length-1];append('picture',{uri,type:image/${fileType}
,name:file-name.${fileType}
});获取(http://52.231.70.40/api/file/uploadReceipt/${ids.id}/${ids.loginId}
,{method:'POST',headers:{'Content Type':'multipart/form data'},body:file})。然后((response)=>response.text())。然后((responseData)=>{console.log(responseData);console.log('file',file)}).done();})错误为400,所需的请求部分“file”不存在@NickRameau@bongjuri1551对不起,我不是想让你在评论中发布它,而是想用它更新你的问题。
// Split the uri by `.` (periods)
const uriParts = uri.split('.');
// Grab the file type at the end of the uri
const fileType = uriParts[uriParts.length - 1];
file.append('picture', {
uri,
type: `image/${fileType}`,
name: 'FILE-NAME.${fileType}`
});