Xóa file bằng Cloud Storage trên nền tảng Apple

Sau khi tải file lên Cloud Storage, bạn cũng có thể xóa chúng.

Xóa một tập tin

Để xóa một tập tin, trước tiên hãy tạo một tham chiếu đến tập tin đó. Sau đó gọi phương thức deleteWithCompletion: trên tham chiếu đó.

Nhanh

// Create a reference to the file to delete
let desertRef = storageRef.child("desert.jpg")

do {
  // Delete the file
  try await desertRef.delete()
} catch {
  // ...
}
    

Mục tiêu-C

// Create a reference to the file to delete
FIRStorageReference *desertRef = [storageRef child:@"images/desert.jpg"];

// Delete the file
[desertRef deleteWithCompletion:^(NSError *error){
  if (error != nil) {
    // Uh-oh, an error occurred!
  } else {
    // File deleted successfully
  }
}];
    

Xử lý lỗi

Có một số lý do có thể xảy ra lỗi khi xóa tệp, bao gồm cả tệp không tồn tại hoặc người dùng không có quyền xóa tệp mong muốn. Bạn có thể tìm thêm thông tin về lỗi trong phần Xử lý lỗi của tài liệu.