uploadImage: function (url, data, successCallback, failCallback) { let formData = new FormData(); for (var i = 0; i < data.length; i++) { let file = {uri: data[i], type: 'multipart/form-data', name: 'a.jpg'}; formData.append("images", file); } fetch(url, { method: 'POST', headers: { 'Content-Type': 'multipart/form-data', }, body: formData, }).then((response)=>response.json()) .then((responseData)=>successCallback(responseData)) .catch((error)=>failCallback(error)) }
问题: iOS正常 安卓报错
原因:如果使用了react-native-image-picker 组件选择图片 是uri的问题
解决方法:
let file = {uri: data[i].uri, type: 'multipart/form-data', name: 'a.jpg'};
如果还是报错 请检查你点到的uri