如何在反应原生中以多部分格式将图像上传到服务器 [英] How to upload images to server with multipart format in react native

查看:68
本文介绍了如何在反应原生中以多部分格式将图像上传到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是本机反应的新手.我想以本机反应将图像上传到服务器.我想以分段格式上传它.所以请帮助我.是否可以以多部分格式将图像上传到服务器是是然后如何.我在谷歌上检查并搜索了很多东西,但我没有找到任何将图像以多部分方式上传到服务器的单一答案.请帮忙.谢谢.

I am new to react native. I want to upload images to server in react native. And I want to upload it in multipart format. so pleas help me. is it possible to upload images to server in multipart format is yes then How. I check and search lots of stuff on google But I did not find any single answer of uploading images to server in multipart. please help. thanks.

推荐答案

我们可以创建一个请求使用 FormData 类以多部分方式将图像上传到服务器.

We can create a request using FormData class to upload images to a server in multipart.

例如:

const formData = new FormData();

formData.append('KEY1', VALUE1);
formData.append('KEY2', VALUE2);
formData.append('upload_pancard', 
  {
    uri: pancardImage.uri,
    name: 'pancardImage.jpg',
    type: 'image/jpg'
  }
);
formData.append('upload_aadhar', 
    {
        uri: upload_aadhar.uri,
        name: 'upload_aadhar.jpg',
        type: 'image/jpg'
    }
);
formData.append('upload_aadhar_second', 
    {
        uri: upload_aadhar_second.uri,
        name: 'upload_aadhar_second.jpg',
        type: 'image/jpg'
    }
);
formData.append('digital_signature', 
    {
        uri: digital_signature.uri,
        name: 'digital_signature.jpg',
        type: 'image/jpg'
    }
);

如果您应该上传多张图片,那么在 formData.append() 中传递数组以上传多张图片.

if you are supposed to upload multiple images then pass the array in the formData.append() to upload multiple images.

这篇关于如何在反应原生中以多部分格式将图像上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆