Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Manchmal läuft nicht alles nach Plan und es kommt zu einem Fehler.
Sehen Sie sich im Zweifelsfall die zurückgegebene Fehlermeldung an.
Im folgenden Code sehen Sie eine benutzerdefinierte Fehlerbehandlung, die den von Cloud Storage zurückgegebenen Fehlercode und die Fehlermeldung untersucht. Solche Fehlerhandler können verschiedenen Objekten hinzugefügt werden, die in der Cloud Storage API verwendet werden (z. B. UploadTask und 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}}
Wenn Sie die Fehlermeldung geprüft haben und Cloud Storage Security Rules für die Aktion vorhanden sind, aber das Problem weiterhin besteht, rufen Sie unsere Supportseite auf und teilen Sie uns mit, wie wir Ihnen helfen können.
Fehlermeldungen behandeln
Es gibt eine Reihe von Gründen, warum Fehler auftreten können, z. B. wenn die Datei nicht vorhanden ist, der Nutzer keine Berechtigung für den Zugriff auf die gewünschte Datei hat oder der Nutzer den Dateiupload abbricht.
Damit Sie das Problem richtig diagnostizieren und den Fehler beheben können, finden Sie hier eine vollständige Liste aller Fehler, die unser Client ausgibt, und wie sie auftreten können. Fehlercodes in dieser Tabelle sind in der Klasse StorageException als Integerkonstanten definiert.
Code
Grund
ERROR_UNKNOWN
Ein unbekannter Fehler ist aufgetreten.
ERROR_OBJECT_NOT_FOUND
Unter der angegebenen Referenz ist kein Objekt vorhanden.
ERROR_BUCKET_NOT_FOUND
Für Cloud Storage ist kein Bucket konfiguriert.
ERROR_PROJECT_NOT_FOUND
Für Cloud Storage ist kein Projekt konfiguriert
ERROR_QUOTA_EXCEEDED
Das Kontingent für Ihren Cloud Storage-Bucket wurde überschritten. Wenn Sie den Spark-Tarif nutzen, sollten Sie ein Upgrade auf den Blaze-Tarif (Pay as you go) in Betracht ziehen. Wenn Sie bereits den Blaze-Tarif nutzen, wenden Sie sich an den Firebase-Support.
Der Nutzer ist nicht authentifiziert. Bitte authentifizieren Sie sich und versuchen Sie es noch einmal.
ERROR_NOT_AUTHORIZED
Der Nutzer ist nicht berechtigt, die angeforderte Aktion auszuführen. Prüfen Sie Ihre Regeln, um sicherzustellen, dass sie korrekt sind.
ERROR_RETRY_LIMIT_EXCEEDED
Das maximale Zeitlimit für einen Vorgang (Hochladen, Herunterladen, Löschen usw.) wurde überschritten. Bitte versuchen Sie es noch einmal.
ERROR_INVALID_CHECKSUM
Die Datei auf dem Client stimmt nicht mit der Prüfsumme der vom Server empfangenen Datei überein. Versuche es noch einmal.
ERROR_CANCELED
Der Nutzer hat den Vorgang abgebrochen.
Wenn Sie versuchen, getReferenceFromUrl() mit einer ungültigen URL aufzurufen, wird außerdem eine IllegalArgumentException ausgelöst. Das Argument für die oben genannte Methode muss das Format gs://bucket/object oder https://firebasestorage.googleapis.com/v0/b/bucket/o/object?token=<TOKEN> haben.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-06 (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`"]]