Expo React Native Fetch API throw "Network request failed" error when turning a base64 image into blob

Viewed 93

I wrote this code:

export default (base64, type = 'application/octet-stream') =>
    fetch(`data:${type};base64,${base64}`).then((res) => res.blob());

in order to transform my base64 image into blob.

my base64 image is coming from this function:

import * as ImagePicker from 'expo-image-picker';

const openImagePickerAsync = async () => {
   ...
   const pickerResult = await ImagePicker.launchImageLibraryAsync({
        mediaTypes: ImagePicker.MediaTypeOptions.All,
        base64: true
    });
   ...
}

this library returns me the base64 image that it did grab from the camera roll, so I can use on the first function I sent to turn into a blob.

the problem is that when I try to do this from my android real device, this fetch api throws "Network request failed" error.

advices? thanks.

0 Answers
Related