如何解决使用react-native-image-picker将图像上传到服务器时出错
今天,我尝试使用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 举报,一经查实,本站将立刻删除。