Laravel REST API图像上传在React Native App中

发布于 2025-01-30 19:35:24 字数 1039 浏览 4 评论 0原文

我可以使用Laravel Rest API上传图像,但是

我正在使用 react-native-image-picker

这是图像拾取器的响应

 LOG  FileName :  {"fileName": "rn_image_picker_lib_temp_ff6cf0af-08b3-41ff-8f76-81a744d42ad4.jpg", 
"fileSize": 37514, "height": 2400, "type": "image/jpeg",
"uri": "file:///data/user/0/com.hometutorsclub/cache/rn_image_picker_lib_temp_ff6cf0af-08b3-41ff-8f76-81a744d42ad4.jpg", "width": 1080}

,使用此方法上传

 var data = new FormData();
  
      data.append('img', {
        uri : imageObj.uri,
        type: imageObj.type,
        name: imageObj.fileName,
      });

此处是API配置上传图像

laravel ret rest API映像上传的配置

使用此配置,映像正正确地上传到邮递员上,但是在React Native App不上传

我认为frontend和后端config notect通信上传

您能帮我帮助我。

I what to upload image using Laravel rest API, but there is some issue

i am using react-native-image-picker

here is the response of image picker

 LOG  FileName :  {"fileName": "rn_image_picker_lib_temp_ff6cf0af-08b3-41ff-8f76-81a744d42ad4.jpg", 
"fileSize": 37514, "height": 2400, "type": "image/jpeg",
"uri": "file:///data/user/0/com.hometutorsclub/cache/rn_image_picker_lib_temp_ff6cf0af-08b3-41ff-8f76-81a744d42ad4.jpg", "width": 1080}

and using this method to upload

 var data = new FormData();
  
      data.append('img', {
        uri : imageObj.uri,
        type: imageObj.type,
        name: imageObj.fileName,
      });

here is API configuration to upload image

Laravel Rest API configuration of image upload

with this config, image is uploading properly on POSTMAN but in React Native app is not uploading

i think frontend and backend config not communicating to upload it

can you please help me where is the issue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱着落日 2025-02-06 19:35:24

当它在邮递员上工作时,这可能是一个标题问题。
在使用Postman发送请求时,请查看隐藏的生成的标题,并找出您的React请求中错过的标题。
最有可能是一个内容类型的问题。上传图像时,我可以在邮递员的标题中看到此标头:

Content-Type: multipart/form-data; boundary=<calculated when request is sent>

As It's working on Postman, it may be a header issue.
While sending your request using Postman, take a look at the hidden generated headers and find out which one is missed in your react request.
Most likely, it is a Content-Type issue. I can see this header in my Postman headers while uploading an image:

Content-Type: multipart/form-data; boundary=<calculated when request is sent>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文