Open Jacky9425 opened 5 years ago
Try passing a filename to your API like:
let formdata = new `FormData();
formdata.append("", { uri: image.path, name: filename, type: image.mime });
The filename can be anything you like.
any success ?
same with me. My server can't find the filename but sometimes it success
@Standin-Alone Have you tried passing a filename as I have mentioned in my comment above? Can you show me the code that you're using to construct the formdata?
i tried it but still unsuccessfull.
I have the same problem, 2 days I couldn't solve it. on IOS works like a charm, but on android sometimes it successes and sometimes it fails with network error. I tried a lot of things (Axios, fetch, XHR and react-native-fs) I also tried adding usesesClearTexts to android manifest, I tried commenting initializeFlipper in mainApllication.java which seems working for a lot of people. Unfortunately, nothing worked for me.
"react-native": "0.66.3"
"react-native-image-crop-picker": "^0.37.1"
"axios": "^0.24.0"
Upload code
const data = new FormData();
data.append('file', {
name: file.name,
type: file. mime,
uri: Platform.OS === 'android' ? file.uri : file.uri.replace('file://', ''),
});
// api is axios instance with authorization
const response = await api.post(url, data,
{
headers: {
'Content-Type': 'multipart/form-data',
},
},
);
I'm facing the same issue. Can't find any solution yet. Image upload is working fine in ios but not in android. Tried all solution but nothing works. "react-native-image-crop-picker": "^0.36.2", "react-native": "0.68.2", "axios": "^0.27.2", Please help me out if anyone find any solution .Thanks
Same issue for me also.
When u see the selected file object:
{
"height": 3000,
"mime": "image/jpeg",
"modificationDate": "1678966724000",
"path": "file:///storage/emulated/0/Android/data/appname/files/Pictures/image-16192248104.jpg",
"size": 7275035,
"width": 4000
}
this height and width is the issue. If you give height+width in the property, this crash will not come. But giving height+width more than 900*900 also may give a crash. so you have to check it.
like this way
ImagePicker.openPicker({
width: 300,
height: 400,
cropping: true
}).then(image => {
console.log(image);
});
@Hitesh2297 that worked for me, do you have explanation why?
When i upload image then getting network error in the API response some time and some time working in only Android. In iOS working fine how to fix this issue? my libraries version "react-native": "0.73.4", "axios": "^1.6.7", "react-native-image-crop-picker": "^0.40.3",
Please help me out if anyone find any solution .Thanks
Hi, i have encounter a untraceable issue. Whenever i pick an image from gallery or capture an image from camera, and immediately perform a upload function (using form post method to store into DB), there is a small probability that i will get a failure response (from the api). I have checked everything and the parameters, all of them are fine, even for the image uri and path.
Mostly i get an failure to upload if the image was taken from camera, may i know what is making the mess here?
Real time scenario, out of 8 uploads, maybe 2 will be failed.