react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

[ANDROID] uploading image to server, sometimes failed sometimes success

Open Jacky9425 opened this issue 6 years ago • 11 comments

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.

Jacky9425 avatar Jun 14 '19 08:06 Jacky9425

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.

kwstasarva avatar Jul 29 '19 15:07 kwstasarva

any success ?

dev3288 avatar Sep 20 '19 12:09 dev3288

same with me. My server can't find the filename but sometimes it success

JE-Zenarosa avatar Oct 12 '19 15:10 JE-Zenarosa

@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?

kwstasarva avatar Oct 22 '19 09:10 kwstasarva

i tried it but still unsuccessfull.

JE-Zenarosa avatar Nov 11 '19 10:11 JE-Zenarosa

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',
      },
    },
  );

naderalfakesh avatar Dec 07 '21 20:12 naderalfakesh

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

ahsanbhatti98 avatar Jul 25 '22 19:07 ahsanbhatti98

Same issue for me also.

krushalikevadiya avatar Jan 20 '23 13:01 krushalikevadiya

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 avatar Mar 16 '23 11:03 Hitesh2297

@Hitesh2297 that worked for me, do you have explanation why?

professorkolik avatar Mar 28 '23 09:03 professorkolik

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",

Screenshot 2024-03-11 at 9 21 24 AM

Please help me out if anyone find any solution .Thanks

denisha25 avatar Mar 11 '24 03:03 denisha25