Firebase Demo Day is here!
Watch demos of how to build and grow AI-powered, full stack apps using the best of Google.
提供意見
使用 Web 上的 Cloud Storage 刪除文件
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
將檔案上傳到雲端儲存後,您也可以刪除它們。
注意: 預設情況下,Cloud Storage 儲存桶需要 Firebase 驗證才能對儲存體桶的資料或檔案執行任何操作。您可以變更 Cloud Storage 的 Firebase 安全規則 以允許未經身份驗證的存取。由於 Firebase 和您專案的預設 App Engine 應用程式共用此儲存桶,因此配置公共存取權限也可以使新上傳的 App Engine 檔案也可公開存取。設定身份驗證時,請務必再次限制對 Cloud Storage 儲存桶的存取。 刪除文件 若要刪除文件,請先建立對該文件的引用 。然後對該參考呼叫delete()
方法,該方法傳回一個可解析的Promise
,如果Promise
拒絕則傳回錯誤。
Web modular API import { getStorage, ref, deleteObject } from "firebase/storage";
const storage = getStorage();
// Create a reference to the file to delete
const desertRef = ref(storage, 'images/desert.jpg');
// Delete the file
deleteObject(desertRef).then(() => {
// File deleted successfully
}).catch((error) => {
// Uh-oh, an error occurred!
}); Web namespaced API // Create a reference to the file to delete
var desertRef = storageRef.child('images/desert.jpg');
// Delete the file
desertRef.delete().then(() => {
// File deleted successfully
}).catch((error) => {
// Uh-oh, an error occurred!
}); 注意: 刪除檔案是永久性操作!如果您想恢復已刪除的文件,請務必備份您的文件,或在您的 Cloud Storage 儲存桶上啟用物件版本控制 。 處理錯誤 文件刪除時可能發生錯誤的原因有很多,包括文件不存在,或是使用者沒有刪除所需文件的權限。有關錯誤的更多資訊可以在文件的處理錯誤 部分找到。
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2023-12-01 (世界標準時間)。
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"缺少我需要的資訊"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"過於複雜/步驟過多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"過時"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻譯問題"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/程式碼問題"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"容易理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"確實解決了我的問題"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
想進一步說明嗎?