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