插件選擇是react-native-image-picker,還挺好用的,不過須要分ios和android不一樣平臺去配置. react
能夠看看以前的文章https://segmentfault.com/a/11...android
如今給出git上的react-native-image-picker地址ios
處理單張圖片git
let formData = new FormData();//若是須要上傳多張圖片,須要遍歷數組,把圖片的路徑數組放入formData中 let file = {uri: response.uri, type: 'multipart/form-data', name: 'image.png'}; //這裏的key(uri和type和name)不能改變, formData.append("files",file); //這裏的files就是後臺須要的key
多張圖片處理github
let formData = new FormData();json
for(var i = 0;i<imgAry.length;i++){ let file = {uri: imgAry[i], type: 'multipart/form-data', name: 'image.png'}; formData.append("files",file); }
uploadURL上傳圖片的地址segmentfault
fetch(uploadURL,{ method:'POST', headers:{ 'Content-Type':'multipart/form-data', }, body:formData, }) .then((response) => response.json()) .then((responseData)=>{ let source = ret.data.images[0].oUrl console.log(source) //獲得的uri(http格式)拿到後進行操做吧 }) .catch((error)=>{console.error('error',error)});
引入模塊和上傳地址
react-native
應用數組