fetching loacal files is causing staus 0 error

I need to connvert image to blob after selecting the image with expo-image-picker the convert to blob using fetch but it is causing the following error.

SDK version 49
Platforms : android

ERROR RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]., js engine: hermes

This is my current situation :

import { Button, StyleSheet, Text, View } from 'react-native';
import * as ImagePicker from 'expo-image-picker'
export default function App() {
  const PickImage = async()=>{
    let result = await ImagePicker.launchImageLibraryAsync({
      quality:1,
      mediaTypes:ImagePicker.MediaTypeOptions.Images,
    })
    if(!result.canceled){
      let response = await fetch(result.assets[0].uri);
      let blob = await response.blob();
      
      //code to upload image
    }
  }
  return (
    <View style={styles.container}>
      <Button onPress={PickImage} title='TEST'/>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

the fetch ststement is causing error. let response = await fetch(result.assets[0].uri);

it is working fine on snack, but causing issues on my local setup

same here. did you found a solution

For some reason this occurs for me when working with Android but it functions fine with iOS. I wonder if it has anything to do with the format of the uri?

Hi, did you solve it. :frowning: i get the same error.

Same error

I solved this by downgrading the whatwg-fetch because the new verison RN72 upgrades whatwg-fetch to 3.6.17 and causes this type of error.Need to install the version 3.6.2 by npm install whatwg-fetch@3.6.2 or npm install --force whatwg-fetch@3.6.2 and for me solved this error.

1 Like

Thank you Anid!!

1 Like

This has been answered over on StackOverflow:

React Native Blob fetch throws error: Failed to construct ‘Response’: The status provided (0) is outside the range [200, 599]

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.