我使用 react native 和 firebase (v9) 將影像上傳到 firebase。在 firebase 存盤中,檔案已上傳,但大小僅為 9 位元組,因此無法正常打開。我不知道如何解決這個問題:S
const uploadFiles = (file, name, storeKey) => {
if(!file){
console.log('no file exists')
return;
}
const exe = file.substring(file.lastIndexOf('.'));
const fileName = name exe;
const storageRef = ref(storage, `/files/${fileName}`);
const uploadTask = uploadBytesResumable(storageRef, file);
uploadTask.on('state_changed', null,
(error) => {
alert(error);
},
() => {
getDownloadURL(uploadTask.snapshot.ref)
.then((URL) => {
setDoc(doc(db, 'Store', storeKey, 'coffeeDB', name), {postImage: URL}, {merge: true});
console.log('url registered')
});
}
)
}
uj5u.com熱心網友回復:
鑒于您正在呼叫file.substring(...),這似乎file是一個檔案名。您不能僅通過傳遞檔案名稱來上傳檔案,因為這存在安全風險。相反,您需要Blob | Uint8Array | ArrayBuffer按照此處和此處所示傳遞 a ,通常是通過傳遞File從中獲取檔案名的參考。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/398858.html
標籤:javascript 火力基地 反应原生 火力存储
