ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.09k stars 1.55k forks source link

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

Open Jacky9425 opened 5 years ago

Jacky9425 commented 5 years ago

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.

kwstasarva commented 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.

dev3288 commented 4 years ago

any success ?

Standin-Alone commented 4 years ago

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

kwstasarva commented 4 years ago

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

Standin-Alone commented 4 years ago

i tried it but still unsuccessfull.

naderalfakesh commented 2 years ago

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',
      },
    },
  );
ahsanbhatti98 commented 2 years ago

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

krushalikevadiya commented 1 year ago

Same issue for me also.

Hitesh2297 commented 1 year ago

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);
});
professorkolik commented 1 year ago

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

denisha25 commented 6 months ago

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