提供意見
在 Android 上使用 Cloud Storage 刪除檔案
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
將檔案上傳至 Cloud Storage 後,也可以刪除檔案。
注意: 根據預設,Cloud Storage 值區會要求 Firebase 驗證,對值區的資料或檔案執行任何動作。您可以變更 Cloud Storage 的 Firebase 安全性規則 ,允許在未經驗證的情況下存取。由於 Firebase 和專案的預設 App Engine 應用程式會共用這個值區,因此設定公開存取權可能也會讓新上傳的 App Engine 檔案可公開存取。設定驗證功能時,請務必再次限制 Cloud Storage 值區的存取權。 刪除檔案
如要刪除檔案,請先建立該檔案的參照 。然後對該參照呼叫 delete()
方法。
Kotlin+KTX
// Create a storage reference from our app
val storageRef = storage.reference
// Create a reference to the file to delete
val desertRef = storageRef.child("images/desert.jpg")
// Delete the file
desertRef.delete().addOnSuccessListener {
// File deleted successfully
}.addOnFailureListener {
// Uh-oh, an error occurred!
}
Java
// Create a storage reference from our app
StorageReference storageRef = storage.getReference();
// Create a reference to the file to delete
StorageReference desertRef = storageRef.child("images/desert.jpg");
// Delete the file
desertRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// File deleted successfully
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Uh-oh, an error occurred!
}
});
注意: 刪除檔案後即無法復原!如果您想還原已刪除的檔案,請務必備份檔案,或在 Cloud Storage 值區中啟用物件版本管理 功能。 處理錯誤
導致檔案刪除發生錯誤的原因有很多,包括檔案不存在,或是使用者沒有刪除所需檔案的權限。如要進一步瞭解錯誤,請參閱說明文件的「處理錯誤 」一節。
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-07-15 (世界標準時間)。
[{
"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":"其他"
}]
想進一步說明嗎?