معالجة الأخطاء في Cloud Storage على Flutter
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
في بعض الأحيان، عند إنشاء تطبيق، لا تسير الأمور كما هو مخطّط لها ويحدث خطأ.
في حال الشك، يمكنك رصد الاستثناء الذي تعرضه الدالة
ومعرفة ما تقوله رسالة الخطأ.
final storageRef = FirebaseStorage.instance.ref().child("files/uid");
try {
final listResult = await storageRef.listAll();
} on FirebaseException catch (e) {
// Caught an exception from Firebase.
print("Failed with error '${e.code}': ${e.message}");
}
التعامل مع رسائل الخطأ
هناك عدة أسباب قد تؤدي إلى حدوث أخطاء، بما في ذلك عدم توفّر الملف أو عدم توفّر إذن للمستخدم بالوصول إلى الملف المطلوب أو إلغاء المستخدم لعملية تحميل الملف.
لتشخيص المشكلة ومعالجة الخطأ بشكل صحيح، إليك قائمة كاملة بجميع الأخطاء التي سيبلغ عنها العميل وكيفية حدوثها.
الرمز |
الوصف |
storage/unknown |
حدث خطأ غير معروف. |
storage/object-not-found |
لا يتوفّر أي عنصر في المرجع المطلوب. |
storage/bucket-not-found |
لم يتم إعداد أي حزمة في Cloud Storage |
storage/project-not-found |
لم يتم إعداد أي مشروع لخدمة Cloud Storage |
storage/quota-exceeded |
تم تجاوز الحصة المخصّصة لحزمة Cloud Storage. إذا كنت تستخدم خطة أسعار Spark، ننصحك بالترقية إلى خطة أسعار Blaze بنظام الدفع حسب الاستخدام. إذا كنت مشتركًا في خطة أسعار Blaze، يُرجى التواصل مع فريق دعم Firebase.
ملاحظة مهمة: اعتبارًا من 1 أكتوبر 2025، يجب الاشتراك في خطة أسعار Blaze لاستخدام Cloud Storage، حتى الحِزم التلقائية. |
storage/unauthenticated |
لم تتم مصادقة المستخدم، يُرجى المصادقة والمحاولة مرة أخرى. |
storage/unauthorized |
المستخدم غير مسموح له بتنفيذ الإجراء المطلوب، يُرجى التحقّق من قواعد الأمان للتأكّد من صحتها. |
storage/retry-limit-exceeded |
تم تجاوز الحدّ الأقصى للوقت المسموح به لإجراء عملية (تحميل أو تنزيل أو حذف أو غير ذلك). يُرجى محاولة التحميل مرة أخرى. |
storage/invalid-checksum |
لا يتطابق الملف على الجهاز مع المجموع الاختباري للملف الذي تلقّاه الخادم. يُرجى محاولة التحميل مرة أخرى. |
storage/canceled |
ألغى المستخدِم العملية. |
storage/invalid-event-name |
تم تقديم اسم حدث غير صالح. يجب أن تكون إحدى القيم التالية: [running ، progress ، pause ] |
storage/invalid-url |
تم تقديم عنوان URL غير صالح إلى refFromURL() . يجب أن يكون التنسيق: gs://bucket/object أو https://firebasestorage.googleapis.com/v0/b/bucket/o/object?token=<TOKEN> |
storage/invalid-argument |
يجب أن تكون الوسيطة التي تم تمريرها إلى put() هي File أو Blob أو UInt8 Array. يجب أن تكون الوسيطة التي تم تمريرها إلى putString() سلسلة أولية أو Base64 أو Base64URL . |
storage/no-default-bucket |
لم يتم ضبط أي مجموعة في خاصية storageBucket ضمن الإعدادات. |
storage/cannot-slice-blob |
يحدث هذا الخطأ عادةً عندما يتغير الملف المحلي (يتم حذفه أو حفظه مرة أخرى أو غير ذلك). يُرجى محاولة التحميل مرة أخرى بعد التأكّد من عدم تغيير الملف. |
storage/server-file-wrong-size |
لا يتطابق حجم الملف على الجهاز مع حجم الملف الذي تلقّاه الخادم. يُرجى محاولة التحميل مرة أخرى. |
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["\u003cbr /\u003e\n\nSometimes when you're building an app, things don't go as planned and an\nerror occurs!\n\nWhen in doubt, catch the exception thrown by the function\nand see what the error message has to say. \n\n final storageRef = FirebaseStorage.instance.ref().child(\"files/uid\");\n try {\n final listResult = await storageRef.listAll();\n } on FirebaseException catch (e) {\n // Caught an exception from Firebase.\n print(\"Failed with error '${e.code}': ${e.message}\");\n }\n\n| **Note:** By default, a Cloud Storage for Firebase bucket requires Firebase Authentication to perform any action on the bucket's data or files. You can change your Firebase Security Rules for Cloud Storage to [allow unauthenticated access for specific situations](/docs/storage/security/rules-conditions#public). However, for most situations, we strongly recommend [restricting access and setting up robust security rules](/docs/storage/security/get-started) (especially for production apps). Note that if you use Google App Engine and have a default Cloud Storage bucket with a name format of `*.appspot.com`, you may need to consider [how your security rules impact access to App Engine files](/docs/storage/gcp-integration#security-rules-and-app-engine-files).\n\nHandle Error Messages\n\nThere are a number of reasons why errors may occur, including the file\nnot existing, the user not having permission to access the desired file, or the\nuser cancelling the file upload.\n\nTo properly diagnose the issue and handle the error, here is a full list of\nall the errors our client will raise, and how they occurred.\n\n| Code | Description |\n|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `storage/unknown` | An unknown error occurred. |\n| `storage/object-not-found` | No object exists at the desired reference. |\n| `storage/bucket-not-found` | No bucket is configured for Cloud Storage |\n| `storage/project-not-found` | No project is configured for Cloud Storage |\n| `storage/quota-exceeded` | Quota on your Cloud Storage bucket has been exceeded. If you're on the Spark pricing plan, consider upgrading to the [pay-as-you-go Blaze pricing plan](/pricing). If you're already on the Blaze pricing plan, reach out to Firebase Support. **Important** : Starting October 1, 2025, the [Blaze pricing plan will be *required* to use Cloud Storage](/docs/storage/faqs-storage-changes-announced-sept-2024), even default buckets. |\n| `storage/unauthenticated` | User is unauthenticated, please authenticate and try again. |\n| `storage/unauthorized` | User is not authorized to perform the desired action, check your security rules to ensure they are correct. |\n| `storage/retry-limit-exceeded` | The maximum time limit on an operation (upload, download, delete, etc.) has been excceded. Try uploading again. |\n| `storage/invalid-checksum` | File on the client does not match the checksum of the file received by the server. Try uploading again. |\n| `storage/canceled` | User canceled the operation. |\n| `storage/invalid-event-name` | Invalid event name provided. Must be one of \\[`running`, `progress`, `pause`\\] |\n| `storage/invalid-url` | Invalid URL provided to `refFromURL()`. Must be of the form: `gs://bucket/object` or `https://firebasestorage.googleapis.com/v0/b/bucket/o/object?token=\u003cTOKEN\u003e` |\n| `storage/invalid-argument` | The argument passed to `put()` must be `File`, `Blob`, or `UInt8` Array. The argument passed to `putString()` must be a raw, `Base64`, or `Base64URL` string. |\n| `storage/no-default-bucket` | No bucket has been set in your config's `storageBucket` property. |\n| `storage/cannot-slice-blob` | Commonly occurs when the local file has changed (deleted, saved again, etc.). Try uploading again after verifying that the file hasn't changed. |\n| `storage/server-file-wrong-size` | File on the client does not match the size of the file received by the server. Try uploading again. |"]]