使用 Unity 適用的 Cloud Storage 刪除檔案

本頁面說明如何使用 Cloud Storage for Firebase SDK 刪除已上傳至 Cloud Storage bucket 的檔案。

刪除檔案

如要刪除檔案,請先建立該檔案的參照。然後對該參照呼叫 DeleteAsync() 方法。

// Create a reference to the file to delete.
StorageReference desertRef = storageRef.Child("images/desert.jpg");

// Delete the file
desertRef.DeleteAsync().ContinueWithOnMainThread(task => {
    if (task.IsCompleted) {
        Debug.Log("File deleted successfully.");
    }
    else {
        // Uh-oh, an error occurred!
    }
});

錯誤處理

刪除檔案時可能發生錯誤的原因有很多,包括檔案不存在,或使用者沒有刪除目標檔案的權限。如要進一步瞭解錯誤,請參閱「處理錯誤」。