Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sau khi tải tệp lên Cloud Storage, bạn cũng có thể xoá những tệp đó.
Xoá tệp
Để xóa một tệp, trước tiên
tạo tệp đối chiếu
cho tệp đó. Sau đó, hãy gọi phương thức delete() trên tham chiếu đó. Phương thức này sẽ trả về một Promise phân giải hoặc một lỗi nếu Promise từ chối.
Web
import{getStorage,ref,deleteObject}from"firebase/storage";conststorage=getStorage();// Create a reference to the file to deleteconstdesertRef=ref(storage,'images/desert.jpg');// Delete the filedeleteObject(desertRef).then(()=>{// File deleted successfully}).catch((error)=>{// Uh-oh, an error occurred!});
// Create a reference to the file to deletevardesertRef=storageRef.child('images/desert.jpg');// Delete the filedesertRef.delete().then(()=>{// File deleted successfully}).catch((error)=>{// Uh-oh, an error occurred!});
Có một số lý do khiến lỗi có thể xảy ra khi xoá tệp,
bao gồm tệp không tồn tại hoặc người dùng không có quyền
để xoá tệp mong muốn. Bạn có thể xem thêm thông tin về các lỗi trong
Xử lý lỗi
của phần Tài liệu.