Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Terkadang beberapa hal tidak berjalan sesuai rencana dan terjadi error.
Jika merasa ragu, periksa error yang ditampilkan, lalu lihat isi pesannya.
Kode berikut menunjukkan implementasi pengendali error khusus yang memeriksa kode error dan pesan error yang ditampilkan oleh Cloud Storage. Pengendali error tersebut dapat ditambahkan ke beragam objek yang digunakan dalam Cloud Storage API (misalnya, UploadTask dan FileDownloadTask).
Kotlin
internalinnerclassMyFailureListener:OnFailureListener{overridefunonFailure(exception:Exception){valerrorCode=(exceptionasStorageException).errorCodevalerrorMessage=exception.message// test the errorCode and errorMessage, and handle accordingly}}
classMyFailureListenerimplementsOnFailureListener{@OverridepublicvoidonFailure(@NonNullExceptionexception){interrorCode=((StorageException)exception).getErrorCode();StringerrorMessage=exception.getMessage();// test the errorCode and errorMessage, and handle accordingly}}
Jika Anda telah memeriksa pesan error dan memiliki Cloud Storage Security Rules yang mengizinkan tindakan Anda, tetapi masih kesulitan dalam memperbaiki error tersebut, buka halaman Dukungan dan beri tahu kami bantuan apa yang diperlukan.
Menangani Pesan Error
Ada sejumlah alasan terjadinya error, di antaranya adalah tidak adanya file, pengguna tidak memiliki izin untuk mengakses file yang diinginkan, atau pengguna membatalkan upload file.
Untuk mendiagnosis masalah dan menangani error dengan tepat, baca daftar lengkap berikut yang berisi semua error yang mungkin dialami klien kami, beserta penyebab setiap error. Kode error dalam tabel ini
ditentukan dalam class StorageException sebagai konstanta bilangan bulat.
Kode
Alasan
ERROR_UNKNOWN
Terjadi error tak dikenal.
ERROR_OBJECT_NOT_FOUND
Tidak ada objek pada referensi yang ditentukan.
ERROR_BUCKET_NOT_FOUND
Tidak ada bucket yang dikonfigurasi untuk Cloud Storage
ERROR_PROJECT_NOT_FOUND
Tidak ada project yang dikonfigurasi untuk Cloud Storage
ERROR_QUOTA_EXCEEDED
Kuota di bucket Cloud Storage telah terlampaui. Jika Anda menggunakan paket harga Spark, pertimbangkan untuk mengupgrade ke paket harga Blaze bayar sesuai penggunaan. Jika Anda sudah menggunakan paket harga Blaze, hubungi Dukungan Firebase.
Pengguna tidak terautentikasi. Autentikasi pengguna, lalu coba lagi.
ERROR_NOT_AUTHORIZED
Pengguna tidak memiliki izin untuk melakukan tindakan yang diminta. Periksa aturan Anda untuk memastikan bahwa aturan tersebut sudah benar.
ERROR_RETRY_LIMIT_EXCEEDED
Anda telah melebihi batas waktu maksimum suatu operasi (upload, download, hapus, dll.). Coba lagi.
ERROR_INVALID_CHECKSUM
File pada klien tidak cocok dengan checksum file yang diterima oleh server. Coba upload lagi.
ERROR_CANCELED
Pengguna membatalkan operasi.
Selain itu, IllegalArgumentException akan ditampilkan jika getReferenceFromUrl() dipanggil
dengan URL yang tidak valid. Argumen untuk
metode di atas harus berupa gs://bucket/object atau
https://firebasestorage.googleapis.com/v0/b/bucket/o/object?token=<TOKEN>
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-05 UTC."],[],[],null,["\u003cbr /\u003e\n\nSometimes things don't go as planned and an error occurs.\n\nWhen in doubt, check the error returned and see what the error message says.\nThe following code shows a custom error handler implementation that inspects\nthe error code and error message returned by Cloud Storage. Such error\nhandlers can be added to various objects used in the Cloud Storage API (for\nexample, `UploadTask` and `FileDownloadTask`). \n\nKotlin \n\n```kotlin\ninternal inner class MyFailureListener : OnFailureListener {\n override fun onFailure(exception: Exception) {\n val errorCode = (exception as StorageException).errorCode\n val errorMessage = exception.message\n // test the errorCode and errorMessage, and handle accordingly\n }\n}https://github.com/firebase/snippets-android/blob/b694d4dbd411d31be39655f47691c3e9f3529b03/storage/app/src/main/java/com/google/firebase/referencecode/storage/kotlin/StorageActivity.kt#L492-L498\n```\n\nJava \n\n```java\nclass MyFailureListener implements OnFailureListener {\n @Override\n public void onFailure(@NonNull Exception exception) {\n int errorCode = ((StorageException) exception).getErrorCode();\n String errorMessage = exception.getMessage();\n // test the errorCode and errorMessage, and handle accordingly\n }\n}https://github.com/firebase/snippets-android/blob/b694d4dbd411d31be39655f47691c3e9f3529b03/storage/app/src/main/java/com/google/firebase/referencecode/storage/StorageActivity.java#L618-L625\n```\n\nIf you've checked the error message and have Cloud Storage Security Rules that allow your\naction, but are still struggling to fix the error, visit our\n[Support page](/support) and let us know how we can help.\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 all\nthe errors our client will raise, and how they can occur. Error codes in this\ntable are defined in the `StorageException` class as integer constants.\n\n| Code | Reason |\n|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ERROR_UNKNOWN` | An unknown error occurred. |\n| `ERROR_OBJECT_NOT_FOUND` | No object exists at the specified reference. |\n| `ERROR_BUCKET_NOT_FOUND` | No bucket is configured for Cloud Storage |\n| `ERROR_PROJECT_NOT_FOUND` | No project is configured for Cloud Storage |\n| `ERROR_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| `ERROR_NOT_AUTHENTICATED` | User is unauthenticated, please authenticate and try again. |\n| `ERROR_NOT_AUTHORIZED` | User is not authorized to perform the requested action, check your rules to ensure they are correct. |\n| `ERROR_RETRY_LIMIT_EXCEEDED` | The maximum time limit on an operation (upload, download, delete, etc.) has been excceded. Try again. |\n| `ERROR_INVALID_CHECKSUM` | File on the client does not match the checksum of the file received by the server. Try uploading again. |\n| `ERROR_CANCELED` | User canceled the operation. |\n\nAdditionally, attempting to call `getReferenceFromUrl()` with an invalid URL\nwill result in an `IllegalArgumentException` from being thrown. The argument to\nthe above method must be of the form `gs://bucket/object` or\n`https://firebasestorage.googleapis.com/v0/b/bucket/o/object?token=\u003cTOKEN\u003e`"]]