我正在嘗試使用React Native“expo”將多個圖像上傳到Firebase存儲和Firebase數據庫集合,但這很困難,我什至嘗試使用chatGpt,但生成的代碼令人困惑並且不知何故過時,因此它不起作用在此處輸入圖像描述
我為此寫了一個函數。這裡是:
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) } }
我為此寫了一個函數。這裡是: