بعد تحميل الملفات إلى Cloud Storage ، يمكنك أيضًا حذفها.
حذف ملف
لحذف ملف ، قم أولاً بإنشاء مرجع لهذا الملف. ثم قم باستدعاء طريقة delete()
على هذا المرجع ، والتي تُرجع Promise
يتم حله ، أو خطأ إذا تم رفض Promise
.
Web modular API
import { getStorage, ref, deleteObject } from "firebase/storage"; const storage = getStorage(); // Create a reference to the file to delete const desertRef = ref(storage, 'images/desert.jpg'); // Delete the file deleteObject(desertRef).then(() => { // File deleted successfully }).catch((error) => { // Uh-oh, an error occurred! });
Web namespaced API
// Create a reference to the file to delete var desertRef = storageRef.child('images/desert.jpg'); // Delete the file desertRef.delete().then(() => { // File deleted successfully }).catch((error) => { // Uh-oh, an error occurred! });
معالجة الأخطاء
هناك عدد من الأسباب لحدوث أخطاء في حذف الملف ، بما في ذلك الملف غير موجود ، أو عدم حصول المستخدم على إذن لحذف الملف المطلوب. يمكن العثور على مزيد من المعلومات حول الأخطاء في قسم معالجة الأخطاء في المستندات.