提供意見
使用 Web 上的 Cloud Storage 刪除文件
將文件上傳到 Cloud Storage 後,您也可以將其刪除。
注意: 默認情況下,Cloud Storage 存儲分區需要 Firebase 身份驗證才能對存儲分區的數據或文件執行任何操作。您可以更改 Cloud Storage 的 Firebase 安全規則 以允許未經身份驗證的訪問。由於 Firebase 和您項目的默認 App Engine 應用共享此存儲分區,因此配置公開訪問權限可能會使新上傳的 App Engine 文件也可以公開訪問。設置身份驗證時,請務必再次限制對 Cloud Storage 存儲分區的訪問。 刪除文件 要刪除文件,首先創建對該文件的引用 。然後在該引用上調用delete()
方法,該方法返回一個解決的Promise
,如果Promise
拒絕,則返回一個錯誤。
Web version 9 詳細了解 可搖樹的 Web v9 模塊化 SDK 並從版本 8升級 。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 version 8 // 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 存儲桶上啟用對象版本控制 。 處理錯誤 刪除文件時可能出現錯誤的原因有很多,包括文件不存在或用戶無權刪除所需文件。有關錯誤的更多信息,請參閱文檔的處理錯誤 部分。
提供意見
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-08-19 UTC.
[{
"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":"其他"
}]
想進一步說明嗎?