Catch up on highlights from Firebase at Google I/O 2023.
Learn more
提供意見
使用 Web 上的 Cloud Storage 刪除文件
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
將文件上傳到雲存儲後,您還可以刪除它們。
注意: 默認情況下,Cloud Storage 存儲桶需要 Firebase 身份驗證才能對存儲桶的數據或文件執行任何操作。您可以更改 Cloud Storage 的 Firebase 安全規則 以允許未經身份驗證的訪問。由於 Firebase 和您項目的默認 App Engine 應用程序共享此存儲桶,因此配置公共訪問權限可能會使新上傳的 App Engine 文件也可公開訪問。設置身份驗證時,請務必再次限制對您的 Cloud Storage 存儲桶的訪問。 刪除文件 要刪除文件,首先創建對該文件的引用 。然後對該引用調用delete()
方法,它返回一個解決的Promise
,如果Promise
拒絕則返回一個錯誤。
Web modular API 了解更多 關於 tree-shakeable 模塊化 Web API 和從命名空間 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-06-02 (世界標準時間)。
[{
"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":"其他"
}]
想進一步說明嗎?