Search code examples
iosimagereact-nativefile-uploadexpo

expo-image-picker gives network request failed when i upload an image in ios but it works fine on android


This is the code that i used to upload images on IOS

  let result = await ImagePicker.launchImageLibraryAsync({
                    mediaTypes: ImagePicker.MediaTypeOptions.Image,
                    allowsEditing: true,
                    quality: 1,
                });

And in the output i got,

Object {
  "cancelled": false,
  "height": 2001,
  "type": "image",
  "uri": "file:///Users/sajid/Library/Developer/CoreSimulator/Devices/A48F2141-D9AF-457A-9D14-D2F2D4B6336B/data/Containers/Data/Application/803F58D8-0CF9-43CA-8972-599C460687B1/Library/Caches/ExponentExperienceData/%2540sajid_542%252FGoTrillo/ImagePicker/19952322-2D5E-495B-A4AF-427EA23663A6.jpg",
  "width": 3000,
}

Till this point it works fine, later when i call fetch on result.uri, it gives me following error on ios ,

const response = await fetch(result.uri);

Output Error: TypeError: Network request failed

This Error is not beinng raise on Android where as in IOS its giving this error when i use the above functions for the second time.Someone please sugggest a fix for this issue.


Solution

  • I found a solution after lots of search on google,

    We need to replace file:// with /private for a fix in ios physical device.

    You can refer this link for extra inforamtion