问题描述
今天,我尝试使用react-native-image-picker
从手机上载图像到服务器,但是我遇到了问题。这是我的代码:
ImagePicker.showImagePicker(options,(response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ',response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ',response.customButton);
} else {
var FormData = require('form-data');
const data = new FormData();
data.append('file',{
uri: `file://${response.path}`,type: response.type,name: response.fileName
});
Axios.post('https://api.hoc68.com/api/v1/upload_files',data,{
headers: {
'Authorization': `Bearer ${stateTree.user.token_key}`,'Content-type': 'multipart/form-data',}
}).then(res => console.log(res.data)).catch(e => console.log(e.response.data))
console.log(response.path + ' ' + response.type);
}
});
运行代码时,出现此错误 Possible Unhandled Promise Rejection (id: 1): TypeError: undefined is not an object (evaluating 'e.response.data')
。有人可以帮助我解决此错误吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)