'React Native expo image picker upload image to firebase storage (v9) crash

i'm trying to upload image selected from expo image picker to firebase storage (since I'm using expo). I checked expo image picker git and found uploadImageAsync for firebase. so I copied it and changed only a little, but somehow it crashes the app most time. Only a few times, it uploaded image properly without any error.

import { storage } from '../firebase'

async function uploadImageAsync(uri, name) {


    const blob = await new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.onload = function () {
            resolve(xhr.response);
        };
        xhr.onerror = function (e) {
            console.log(e);
            reject(new TypeError("Network request failed"));
        };
        xhr.responseType = "blob";
        xhr.open("GET", uri, true);
        xhr.send(null);
    });

    const fileRef = ref(storage, `files/${name}`);
    const result = await uploadBytes(fileRef, blob);

// We're done with the blob, close and release it
    blob.close();

    return await getDownloadURL(fileRef);
}

since the uri comes from image in the phone, uri = file:///Users/~absolute path ~/image name.jpg and this is the link expo image picker for firebase expo image picker for firebase

Problem report says, Terminating with uncaught exception of type NSException Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

edit) I found it's working in android but not not in ios for IOS, I think converting to blob is working. but having error in const result = await uploadBytes(fileRef, blob)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source