I use 'React-native-image-picker' to upload image to my server :
const options = {
title: 'Chọn ảnh đại diện ',
takePhotoButtonTitle: 'Chụp ảnh',
chooseFromLibraryButtonTitle: 'Chọn từ thư viện',
cancelButtonTitle: 'Thoát',
noData: true
};
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(JSON.stringify(e)))
console.log(response.path + ' ' + response.uri + ' ' + response.type);
}
});
When I choose image from my download gallery, everything is fine, the server send the response back with uri. But when I choose image from my camera gallery or when I take a photo with my phone's camera and upload it, Axios
catches this error. When I search this error in Google it says this happens when my file is too large. Can anyone tell me where my problem need to fix is , in my front-end code or my server code ?