我無法從 firebase 存盤中檢索影像。我目前正在我的 expo react 本機專案中集成 Firebase SDK。我使用的 Firebase sdk 版本是 9.6.1。我可以成功使用 Firebase AUTH 和 firebase firestore(檢索和更新資料)。
當我嘗試使用 firebase 的存盤時,我收到了這個奇怪的錯誤:
[未處理的承諾拒絕:FirebaseError:Firebase Storage:要使用 ref(service, url),第一個引數必須是 Storage 實體。(存盤/無效引數)]
這是我初始化我的 firebase 應用程式的地方:
import { initializeApp } from "firebase/app";
export const firebaseConfig = {
apiKey: "apices",
authDomain: "xxxxx.firebaseapp.com",
databaseURL:
"https://xxxxx-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "xxxxx",
storageBucket: "xxxxx.appspot.com",
messagingSenderId: "333333333",
appId: "yyyyyyyyyyy",
measurementId: "fffffff",
};
const app = initializeApp(firebaseConfig);
export { app };
然后做一個簡單的:
const imageRef = ref(getStorage(), imageUrl);
給我一個錯誤。是的 imageUrl 是一個有效的 gs://projectid.appspot.com/folder1/image1.jpg url。
我有什么問題嗎?
uj5u.com熱心網友回復:
您可以嘗試在初始化 Firebase 的同一個檔案中初始化存盤,然后在需要的地方匯入它嗎?在getStorage()目前可能火力地堡之前得到呼叫初始化:
const app = initializeApp(firebaseConfig);
const storage = getStorage(app)l
export { app, storage };
// import { storage } from "../firebase_file.js"
const imageRef = ref(storage, imageUrl);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/404438.html
標籤:
