1

i'm using react-native-vision-camera library and click photo and trying to convert it into blob and then to the base64 while fetch getting this error

Failed to construct 'Response': The status provided (0) is outside the range [200, 599] while fetch

const getBlob = useCallback(fileUri => {
        console.log("fileUri=", "file://" + fileUri)
        return fetch("file://" + fileUri).then(
            response => {
                console.log("getBlob res=>,", response)
                return response.blob()
            },
            error => {
                console.log(`Error in converting image to blob - ${error}`)
            },
        )
    }, [])

    const blobToBase64 = useCallback(blob => {
        try {
            const reader = new FileReader()
            reader.readAsDataURL(blob)
            return new Promise(resolve => {
                reader.onloadend = () => {
                    resolve(reader.result)
                }
            })
        } catch (err) {
            console.log(`Error in converting blob to base64 - ${err}`)
            throw err
        }
    }, [])
    const handleCapture = async () => {

        if (takingPic) return;
        setTakingPic(true);

        try {
            if (cameraRef.current !== null) {
                const photo = await cameraRef.current.takePhoto({});
                console.log("photo=", photo)
                const blob = await getBlob(photo?.path)
                console.log("blob=", blob)

                blobToBase64(blob).then(finalImage => {
                    console.log("finalImage=", finalImage)
                    // setTakingPic(false);
                    props.onPicture(finalImage);
                }
                )

            }
        } catch (e) {
            console.log("handleCapture", e);
        }
    };

provided all functions above it was working previously but suddenly it getting this error unable to find the solution

Yuvraj Chaudhari
  • 191
  • 1
  • 2
  • 10
  • Does this answer your question? [fetching loacal files is causing staus 0 error in react native (expo) app](https://stackoverflow.com/questions/76754693/fetching-loacal-files-is-causing-staus-0-error-in-react-native-expo-app) – FutureJJ Jul 29 '23 at 17:54

0 Answers0