在ReactNative和CodeIgniter中上传文件 [英] File upload in ReactNative and CodeIgniter

查看:58
本文介绍了在ReactNative和CodeIgniter中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提交表单数据并将图像从React Native应用程序上传到CodeIgniter后端服务器.我从 react-native-image-crop-picker 中选择图像,仅发送和保存数据.但不会上传图像.我已经尝试过使用邮递员,它完美地工作.

I'm trying to submit form data and upload images from React Native app to CodeIgniter backend server. I'm choosing the images from react-native-image-crop-picker and only the data is sent and saved. But not the image is uploaded. I have tried this using Postman and it works perfectly.

我看到 form.append()有3个参数.我检查了邮递员的请求代码,它显示如下

I see that form.append() has 3 parameters. I checked the Postman request code, and it shows like this

data.append("attach_report",fileInput.files [0],"... 3539240198157045_n.jpg");

我的问题是, fileInput.files [0] 的数据类型是什么?预先感谢

My problem is, what's the datatype of fileInput.files[0] in this? Thanks in advance

推荐答案

最后,我找到了答案.我已经看到,从 react-native-image-crop-picker 返回的文件几乎是一个File对象.所以我只是像下面那样编辑了文件.

Finally I found an answer for this. I have seen that the file returns from react-native-image-crop-picker is almost a File object. So I just edited the file like below.

// image is react-native-image-crop-picker returning file
image.uri = image.path;
image.name = "TEST.jpg";
image.type = image.mime;
image.dateModified = new Date();

然后

const f = new FormData();
f.append('attach_report', image, image.uri);
f.append('user_id', 1);

然后提交表格.它适用于我的情况...

Then submit the form. It works in my scenario...

这篇关于在ReactNative和CodeIgniter中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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