Xoá tệp bằng Cloud Storage cho C++

Sau khi tải tệp lên Cloud Storage, bạn cũng có thể xoá tệp.

Xoá tệp

Để xoá một tệp, trước tiên, hãy tạo một tệp đối chiếu cho tệp đó. Sau đó, gọi phương thức Delete() trên tệp đối chiếu đó.

// Create a reference to the file to delete.
StorageReference *desert_ref = storage_ref.Child("images/desert.jpg");

// Delete the file
Future future = desert_ref.Delete();

// Wait for operation to complete...

if (future.Error() != firebase::storage::kErrorNone) {
  // Uh-oh, an error occurred!
} else {
  // File deleted successfully
}

Xử lý lỗi

Có một số lý do khiến lỗi có thể xảy ra khi xoá tệp, bao gồm cả việc tệp không tồn tại hoặc người dùng không có quyền xoá tệp được chỉ định. Bạn có thể xem thêm thông tin về lỗi trong phần Xử lý lỗi của tài liệu.