react native 之上传文件
2017-02-20 10:41
211 查看
/* * * 上传图片请求 * @param * @returns * */ uploadImage(imgAry) { let formData = new FormData();<br> //因为需要上传多张图片,所以需要遍历数组,把图片的路径数组放入formData中 for(var i = 0;i<imgAry.length;i++){ let file = {uri: imgAry[i], type: 'multipart/form-data', name: 'image.png'}; //这里的key(uri和type和name)不能改变, formData.append("files",file); //这里的files就是后台需要的key } fetch('http://192.168.0.183:8080/whale/test/upload_files',{ method:'POST', headers:{ 'Content-Type':'multipart/form-data', }, body:formData, }) .then((response) => response.text() ) .then((responseData)=>{ console.log('responseData',responseData); }) .catch((error)=>{console.error('error',error)}); }
其中,关于图片的路径,我的是这样的:
iOS:
file:///Users/shaotingzhou/Library/Developer/CoreSimulator/Devices/9462ED30-88C7-4318-BF83-3914B9314D34/data/Containers/Data/Application/E9A05CAF-AF07-4BA3-B2C3-C2EFBC6C2C6A/Documents/images/D5E1640B-836A-4EC9-A5C2-65B2E4E8CFE0.jpg
Android:
file:///storage/emulated/0/Pictures/image-ec0667ed-ecc5-4eed-928f-26fed6a63860.jpg
相关文章推荐
- React Native文件上传下载
- RN文件上传(仅ios),下载,创建,删除等文件操作(兼容IOS和Android)--react-native-fs
- react-native-qiniu源码修改(实现文件上传,上传策略等)
- React-native文件上传
- 解决 react native 的 webview 组件不支持android客户端上传图片文件问题
- React Native fench FormData 上传文件
- react-native 实现上传功能
- 004-React-Native--多图选择上传
- 《React-Native系列》7、bundle文件的加载和维护
- React-Native配置自定义字体文件
- react-native不是内部或 外部命令,也不是可运行的程序或批处理文件
- RN-第三方-react-native-image-picker,选择图片上传
- 第一节,加载react native js文件的方法和渲染元素
- (十六)ReactNative 中获取当前文件的相对路径和相对路径
- React Native 使用react-native-image-picker插件上传图片详细步骤
- react-native json 上传本地图片及网络图片方法
- 《React-Native系列》40、 ReactNative之bundle文件瘦身
- ReactNative-ios 生成bundle文件
- 《React-Native系列》39、 ReactNative之bundle文件瘦身
- 如何创建一个依赖Android AAR文件的React Native组件