حذف الملفات باستخدام Cloud Storage على الويب

توضّح هذه الصفحة كيفية استخدام حزمة تطوير البرامج (SDK) لـ Cloud Storage for Firebase من أجل حذف الملفات التي تم تحميلها إلى حزمة Cloud Storage.

حذف ملف

لحذف ملف، عليك أولاً إنشاء مرجع لهذا الملف. بعد ذلك، يمكنك استدعاء طريقة delete() في هذا المرجع، والتي تعرض Promise يتم حلّه، أو خطأ إذا تم رفض Promise.

Web

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

// 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!
});

معالجة الأخطاء

هناك عدد من الأسباب التي قد تؤدي إلى حدوث أخطاء في عمليات حذف الملفات، بما في ذلك عدم وجود الملف، أو عدم حصول المستخدم على إذن لحذف الملف المقصود. لمزيد من المعلومات حول الأخطاء، يُرجى الاطّلاع على معالجة الأخطاء.