React Native 表单数据请求失败,未找到多部分边界
我很难使用 Axios 表单数据来反应本机文件上传。我将内容类型设置为 multipart/form-data。以下是我的要求部分。
- 表单数据主体内容
{"_parts":[["profileImage",{"name":"rn_image_picker_lib_temp_51ee6068-2b4b-4baf-a6c3-44b14b0b5b9b.jpg","type":"image/jpeg","uri ":"文件:///data/user/0/com.sentura.xchange/cache/rn_image_picker_lib_temp_51ee6068-2b4b-4baf-a6c3-44b14b0b5b9b.jpg"}],["电子邮件","[电子邮件受保护]"],["firstName","vv"],["lastName","ss"],["地址ss","sdf"],["邮政编码","2323"],["手机号码","0796677653"],["国家/地区","安圭拉"],["国家/地区代码","+1264"]]} ”
- 请求标头
<前><代码>“标题”:{ "接受":"application/json", "授权":"承载者eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ2aWR1OTk2QGdtYWlsLmNvbSIsImV4cCI6MTY0NTk1ODYzNywiaWF0IjoxNjQ1OTU 3NzM3fQ.GZMQFYGU4veH4xZ9ki2afWmtbGCKhOK5JruWLRX75nisVXXX9JmQYf31ns_ALVr9N1-RgcpMabolgHQSMZ7KIw", “内容类型”:“多部分/表单数据” }
但从 Spring Boot 方面来看,它给出了以下错误。但这在邮递员中工作。
org.apache.tomcat.util.http.fileupload.FileUploadException:请求被拒绝,因为未找到多部分边界
希望您的支持解决此问题。谢谢!
I'm struggled with react native file upload using Axios form data. I set the content type as multipart/form-data. below is my request parts.
- form-data body content
{"_parts":[["profileImage",{"name":"rn_image_picker_lib_temp_51ee6068-2b4b-4baf-a6c3-44b14b0b5b9b.jpg","type":"image/jpeg","uri":"file:///data/user/0/com.sentura.xchange/cache/rn_image_picker_lib_temp_51ee6068-2b4b-4baf-a6c3-44b14b0b5b9b.jpg"}],["email","[email protected]"],["firstName","vv"],["lastName","ss"],["address","sdf"],["postalCode","2323"],["mobileNumber","0796677653"],["country","Anguilla"],["countryCode","+1264"]]}"
- request headers
"headers":{ "Accept":"application/json", "Authorization":"Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ2aWR1OTk2QGdtYWlsLmNvbSIsImV4cCI6MTY0NTk1ODYzNywiaWF0IjoxNjQ1OTU3NzM3fQ.GZMQFYGU4veH4xZ9ki2afWmtbGCKhOK5JruWLRX75nisVXXX9JmQYf31ns_ALVr9N1-RgcpMabolgHQSMZ7KIw", "Content-Type":"multipart/form-data" }
but from the spring boot side, it gives the below error. but this work in postman.
org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
Hope your support to resolve this. thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,问题发生在我的 React Native 版本上。我不知道使用最新的 React Native 版本实现它的正确方法是什么。我使用 React Native 0.67。不幸的是,它坏了。
我添加了相同的代码库来响应本机 0.64,并且它按我的预期运行良好。没有对 axios 或任何其他代码进行任何更改。
Actually the issue happened with my react native version. i don't know what is the correct way to achieve it with newest react native versions. i worked with react native 0.67. unfortunately, it's broken.
I added the same code base to react native 0.64 and it worked well as i expected. didn't do any code change to axios or any other.
这对我有用:
This works for me: