提供意見
在 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-23 (世界標準時間)。
[{
"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":"其他"
}]
想進一步說明嗎?