firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.7k stars 3.97k forks source link

🐛 [firebase_storage] An unknown error occurred, please check the server response. #3791

Closed jonmountjoy closed 3 years ago

jonmountjoy commented 4 years ago

Bug report

When awaiting a task, or listening for snapshot events, an exception is thrown with absolutely no detailed information.

The exception has a code of unknown and message of An unknown error occurred, please check the server response. - but there's no way (that I know of) to access the response.

Steps to reproduce

The code seems straightforward:

storage.UploadTask _createUploadTask(
    Uint8List screenshot, String feedback, String uid) {
  final String uuid = Uuid().v1();

  final storage.Reference storageReference = storage.FirebaseStorage.instance
      .ref("/feedback-images")
      .child('$uuid.png');

  final storage.UploadTask uploadTask = storageReference.putData(
      screenshot,
      storage.SettableMetadata(
          contentType: "image/png",
          customMetadata: {"feedback": feedback, "uid": uid}));

  return uploadTask;
}

I call it like so:

   Future.delayed(Duration.zero, () async {
        try {
          storage.TaskSnapshot snapshot = await task;
        } on storage.FirebaseException catch (e) {
          // always fails
          print(e.code);
          print(task.snapshot);
        }
      });

Expected behavior

It would be great if there was a way to find out what was causing this, or have access to the header, as indicated in the underlying message.

Additional context

This used to work before I did an upgrade to ^5.0.0-dev.2


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.15.6 19G2021, locale en-GB) [!] Android toolchain - develop for Android devices (Android SDK version 28.0.3) ✗ Flutter requires Android SDK 29 and the Android BuildTools 28.0.3 To update the Android SDK visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions. [✓] Xcode - develop for iOS and macOS (Xcode 12.0) [✓] Android Studio (version 4.0) [✓] VS Code (version 1.49.3) [✓] Connected device (1 available) ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 2.10.0 Flutter SDK 1.22.0 myapp 1.0.0+1 dependencies: - auto_animated 2.1.0 [flutter visibility_detector] - charts_flutter 0.9.0 [charts_common collection flutter intl logging meta] - cloud_firestore 0.14.1+2 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - connectivity 0.4.9+3 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web] - cupertino_icons 1.0.0 - feedback 0.4.0 [flutter http] - firebase_analytics 6.0.1 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface] - firebase_auth 0.18.1+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter] - firebase_core 0.5.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_storage 5.0.0-dev.2 [flutter firebase_core firebase_core_platform_interface firebase_storage_platform_interface quiver] - flappy_search_bar 1.7.2 [flutter async flutter_staggered_grid_view] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_numpad_widget 0.1.1 [flutter] - flutter_reorderable_list 0.1.4 [flutter] - flutter_slidable 0.5.7 [flutter] - flutter_sticky_header 0.4.6 [flutter value_layout_builder] - google_fonts 1.1.0 [flutter http path_provider crypto pedantic] - google_sign_in 4.5.3 [google_sign_in_platform_interface flutter meta google_sign_in_web] - pedantic 1.9.0 - preferences 5.2.1 [flutter shared_preferences] - provider 4.3.2+2 [flutter nested collection] - quick_actions 0.4.0+7 [flutter meta] - quiver 2.1.3 [matcher meta] - shared_preferences 0.5.10 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web] - sign_in_with_apple 2.5.2 [meta flutter] - sliding_sheet 0.4.0 [flutter] - sounds 1.0.0-beta13 [device_info flutter_spinkit meta path path_provider provider sounds_common uuid flutter] - timeago 2.0.27 - tuple 1.0.3 [quiver] - uuid 2.2.2 [crypto convert] dev dependencies: - flutter_launcher_icons 0.7.5 [image args yaml] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - archive 2.0.13 [crypto args path] - args 1.6.0 - async 2.5.0-nullsafety.1 [collection] - boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner] - characters 1.1.0-nullsafety.3 - charcode 1.2.0-nullsafety.1 - charts_common 0.9.0 [collection intl logging meta vector_math] - clock 1.1.0-nullsafety.1 - cloud_firestore_platform_interface 2.1.1 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.2.0+3 [flutter flutter_web_plugins firebase http_parser meta firebase_core cloud_firestore_platform_interface js] - collection 1.15.0-nullsafety.3 - connectivity_for_web 0.3.1 [connectivity_platform_interface flutter_web_plugins flutter] - connectivity_macos 0.1.0+3 [flutter] - connectivity_platform_interface 1.0.6 [flutter meta plugin_platform_interface] - convert 2.1.1 [charcode typed_data] - crypto 2.1.4 [collection convert typed_data] - device_info 0.4.2+6 [flutter] - fake_async 1.2.0-nullsafety.1 [clock collection] - file 5.2.0 [intl meta path] - firebase 7.3.0 [http http_parser js] - firebase_analytics_platform_interface 1.0.1 [flutter meta] - firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta] - firebase_auth_platform_interface 2.1.0 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.1 [flutter flutter_web_plugins firebase meta http_parser intl firebase_core firebase_auth_platform_interface js] - firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js] - firebase_storage_platform_interface 1.0.0-dev.1 [flutter meta collection firebase_core plugin_platform_interface] - flutter_spinkit 4.1.2+1 [flutter] - flutter_staggered_grid_view 0.3.1 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - google_sign_in_platform_interface 1.1.2 [flutter meta quiver] - google_sign_in_web 0.9.1+1 [google_sign_in_platform_interface flutter flutter_web_plugins meta js] - http 0.12.1 [http_parser path pedantic] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - image 2.1.12 [archive xml] - intl 0.16.1 [path] - js 0.6.2 - logger 0.9.2 - logging 0.11.4 - matcher 0.12.10-nullsafety.1 [stack_trace] - meta 1.3.0-nullsafety.3 - nested 0.0.4 [flutter] - path 1.8.0-nullsafety.1 - path_provider 1.6.11 [flutter path_provider_platform_interface path_provider_macos path_provider_linux] - path_provider_linux 0.0.1+1 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+3 [flutter] - path_provider_platform_interface 1.0.2 [flutter meta platform plugin_platform_interface] - petitparser 2.4.0 [meta] - platform 2.2.1 - plugin_platform_interface 1.0.2 [meta] - process 3.0.13 [file intl meta path platform] - shared_preferences_linux 0.0.2+1 [file flutter meta path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 0.0.1+10 [shared_preferences_platform_interface flutter] - shared_preferences_platform_interface 1.0.4 [meta flutter] - shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta] - sky_engine 0.0.99 - sounds_common 1.0.8 [intl logger meta path pedantic uuid flutter] - source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph] - stack_trace 1.10.0-nullsafety.1 [path] - stream_channel 2.1.0-nullsafety.1 [async] - string_scanner 1.1.0-nullsafety.1 [charcode source_span] - term_glyph 1.2.0-nullsafety.1 - test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0-nullsafety.3 [collection] - value_layout_builder 0.1.0 [flutter] - vector_math 2.1.0-nullsafety.3 - visibility_detector 0.1.5 [flutter] - xdg_directories 0.1.0 [path process flutter] - xml 3.6.1 [collection convert meta petitparser] - yaml 2.2.1 [charcode collection string_scanner source_span] ```

helenaford commented 4 years ago

Hi, thanks for the reporting the issue. We'll look into this as there should be more information. In the meantime, for Android the server response is printed in the console so maybe that can help with debugging.

jonmountjoy commented 4 years ago

Thank you @helenaford - running on Android showed me that it was an access-denied error, probably caused by some bug in Firestore itself (I migrated an account, and it looks like a key permission on the bucket wasn't set).

TahaTesser commented 4 years ago

Hi @jonmountjoy Can you please provide your flutter run --verbose and a complete reproducible minimal code sample Thank you

helenaford commented 4 years ago

This is a bug with storage exceptions, in particular with iOS, and is awaiting on a fix.

jonmountjoy commented 4 years ago

It sounds like @helenaford knows what this is, but if you want more context @TahaTesser , any code that tries to put something in a storage bucket with a particular condition (see below) fails without a useful error.

It doesn't happen for everything. For example, if you try and put something in a bucket that doesn't exist, you get a useful error on iOS:

 [ +263 ms] flutter: snapshot>> 160/176972  TaskSnapshot(ref: Reference(app: [DEFAULT], fullPath: feedback-fimages/f0ca2bd0-097f-11eb-96e4-59ae9b888a8c.png),
state: TaskState.running)
[   +4 ms] flutter: ERROR: [firebase_storage/unauthorized] User is not authorized to perform the desired action.

If, however, there's something wrong with your Storage bucket (I had a permission problem, which wasn't created by me. I guess there's a bug in Firestore somewhere, but I had a problem similar to this one which could only be resolved by adding a firebase-storage@system.gserviceaccount.com as a Storage Admin to the bucket 👎

In this case, if you put an object in the correct bucket, it fails like so:

    [ +310 ms] flutter: snapshot>> 159/176971  TaskSnapshot(ref: Reference(app: [DEFAULT], fullPath: feedback-images/446282f0-0981-11eb-8d5f-633189166802.png),
state: TaskState.running)
    [   +5 ms] flutter: ERROR: [firebase_storage/unknown] An unknown error occurred, please check the server response.

On iOS there is no indicated server response, so it's a useless error.

The same problem on Android, provides a much more useful exception with all the details:

E/StorageException(13016): StorageException has occurred.
E/StorageException(13016): An unknown error occurred, please check the HTTP result code and inner exception for server response.
E/StorageException(13016):  Code: -13000 HttpResult: 400
E/StorageException(13016): The server has terminated the upload session
E/StorageException(13016): java.io.IOException: The server has terminated the upload session
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@19.1.1:331)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@19.1.1:300)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:221)
E/StorageException(13016):  at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
E/StorageException(13016):  at com.google.firebase.storage.StorageTask$$Lambda$12.run(com.google.firebase:firebase-storage@@19.1.1)
E/StorageException(13016):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/StorageException(13016):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/StorageException(13016):  at java.lang.Thread.run(Thread.java:761)
E/StorageException(13016): Caused by: java.io.IOException: {  "error": {    "code": 400,    "message": "Permission denied. Could not access bucket auth-b4615.appspot.com. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources.",    "status": "ACCESS_BUCKET"  }}
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@19.1.1:433)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@19.1.1:450)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@19.1.1:441)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:272)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:286)
E/StorageException(13016):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:70)
E/StorageException(13016):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:62)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@19.1.1:467)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@19.1.1:268)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:216)
E/StorageException(13016):  ... 5 more
E/StorageException(13016): StorageException has occurred.
E/StorageException(13016): An unknown error occurred, please check the HTTP result code and inner exception for server response.
E/StorageException(13016):  Code: -13000 HttpResult: 400
E/StorageException(13016): The server has terminated the upload session
E/StorageException(13016): java.io.IOException: The server has terminated the upload session
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@19.1.1:331)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@19.1.1:300)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:221)
E/StorageException(13016):  at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
E/StorageException(13016):  at com.google.firebase.storage.StorageTask$$Lambda$12.run(com.google.firebase:firebase-storage@@19.1.1)
E/StorageException(13016):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/StorageException(13016):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/StorageException(13016):  at java.lang.Thread.run(Thread.java:761)
E/StorageException(13016): Caused by: java.io.IOException: {  "error": {    "code": 400,    "message": "Permission denied. Could not access bucket auth-b4615.appspot.com. Please enable Firebase Storage for your bucket by visiting the Storage tab in the Firebase Console and ensure that you have sufficient permission to properly provision resources.",    "status": "ACCESS_BUCKET"  }}
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@19.1.1:433)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@19.1.1:450)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@19.1.1:441)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:272)
E/StorageException(13016):  at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@19.1.1:286)
E/StorageException(13016):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:70)
E/StorageException(13016):  at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@19.1.1:62)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@19.1.1:467)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@19.1.1:268)
E/StorageException(13016):  at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@19.1.1:216)
E/StorageException(13016):  ... 5 more
I/flutter (13016): ERROR: [firebase_storage/unknown] An unknown error occurred
oodavid commented 3 years ago

We're periodically seeing the same error with firebase_storage: ^5.0.1 on ios.

[firebase_storage/unknown] An unknown error occurred, please check the server response.

Our files successfully upload on subsequent attempts.

sebasbose commented 3 years ago

Is this a persistent error still? I'm having the same error when uploading Files with a physical device. The only console data I get is: flutter: [firebase_storage/unknown] An unknown error occurred, please check the server response.

davidRuland1234 commented 3 years ago

I also have an issue with Firebase Storage: ^5.0.1 in latest stable, beta and master channel on iOS. I can upload files to Firebase Storage, but I can't return Url with this code. My error is a null value from Servervalue.timestamp on every file that I upload to Firebase Storage and download. Future _uploadFile(Reference ref, File file, [SettableMetadata metadata]) async { String url; TaskSnapshot taskSnapshot; UploadTask uploadTask = ref.putFile(file, metadata); taskSnapshot = await uploadTask.whenComplete(() async { try { var downloadUrl = await taskSnapshot.ref.getDownloadURL(); url = downloadUrl.toString(); } catch (onError) { print("Error"); } }); //final url = await ref.getDownloadURL(); return Future.value(url); //return url; } DateTime dateTimeParser(object) { if (object is String) { return DateTime.parse(object); } else if (object is int) { return DateTime.fromMillisecondsSinceEpoch(object); } else { throw "dateTimeParser() error object is neither String or int"; } }

sebasbose commented 3 years ago

Any updates regarding this issue? I've tried my app on an Android Phone and it worked fine, tried it on an Android simulator and worked fine, tried it on an iOS simulator and worked fine, but when I run it on an iOS physical device it doesn't work. It gets stuck on the 'uploading state'. I. am using. Firebase Storage's latest stable release.

davidRuland1234 commented 3 years ago

I have tried now on a iOS and Android physical device with a latest stable release and its works for user that are already register. However new user that sign up on Firebase Authentication can not upload to Firebase Storage. It worked fine for a week ago and I have not changed my authentication code or Firebase Storage for uploading since then. This is the latest code for uploading that worked for a week ago. Future _uploadFile(Reference ref, File file, [SettableMetadata metadata]) async { String url; final task = ref.putFile(file, metadata); await task.whenComplete(() async => url = await ref.getDownloadURL()); return url;

davidRuland1234 commented 3 years ago

Its working now for some reason. Will check it why.

marcoheine commented 3 years ago

Any Updates? iOS-Simulator works, but on physical Device I have the same problem.

AlexanderMarchant commented 3 years ago

I'm trying to upload a video to Firebase with Swift and I am getting the same error.

Played around with testing this, my code works perfectly when using my iPhone 6 which is running iOS 12.5.1.

I do get this error response when I use my iPhone 11 (real device) / iPhone 12 (simulator) which are both running 14.4.

I hope it helps getting this fixed as this is a huge blocker for a new video feature I am adding to my app.

russellwheatley commented 3 years ago

Hey @jonmountjoy, has the error message since been improved? There has been a few major releases since you raised the issue.

jonmountjoy commented 3 years ago

i'm happy to close this @russellwheatley but note that @helenaford seems to know what the underlying cause is (https://github.com/FirebaseExtended/flutterfire/issues/3791#issuecomment-706539690)

russellwheatley commented 3 years ago

Thanks for reaching out, @jonmountjoy. Will close 👍.

stnguyen90 commented 3 years ago

Can anyone provide any more information or workaround for this? I'm experiencing this on iOS, but not on Android.

jonmountjoy commented 3 years ago

It's been a while now but I opened this bug report because the iOS version wasn't showing any reasons behind the exceptions, so I had a hard to figuring out what the problem was, whereas the Android version did show the reasons.

So I ran the app on Android, and found I had an access-denied issue.

Some people are conflating this bug report with actual access errors. That's a different thing. This report was not about the errors, but about the fact that if there was an error, you couldn't see "why" unless you were running on Android (which is partially solved by just using the Android simulator, I guess).

jamesdixon commented 3 years ago

@helenaford hello, has this been fixed? and is there an issue tracking this elsewhere?

In my case, I am still not seeing the reason the upload failed on iOS:

Screen Shot 2021-05-13 at 8 52 38 AM