Upload multiple images to Firebase collection and Firebase using React Native Expo
P粉226642568
P粉226642568 2024-04-04 23:20:02
0
1
1569

I'm trying to use React Native "expo" to upload multiple images to Firebase Storage and Firebase Database Collections but it's difficult, I even tried using chatGpt but the generated code is confusing and somehow outdated so It doesn't work Enter image description here

P粉226642568
P粉226642568

reply all(1)
P粉322106755

I wrote a function for this. here it is:

import { ref, uploadBytes, getDownloadURL } from 'firebase/storage'
import { auth, storage } from '../../config/firebase'
export async function uploadImage(uri) {
try {
    const response = await fetch(uri)
    const blobFile = await response.blob()

    const image_name = 'image_name'
    const metadata = {
        contentType: 'image/jpeg',
        customMetadata: {
            from: auth?.currentUser?.uid
        }
    }

    const reference = ref(storage, image_name)
    const result = await uploadBytes(reference, blobFile, metadata)
    const url = await getDownloadURL(result.ref)

    return url
} catch (err) {
    return Promise.reject(err)
}
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template