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粉3221067552024-04-05 22:40:27
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) } }