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.71k stars 3.97k forks source link

🐛 [firebase_storage] unknown error #11961

Closed haf closed 10 months ago

haf commented 11 months ago

Bug report

Describe the bug

After upgrading from 10.16 to 10.18 on iOS (via Flutter / firebase_storage), I can't list, upload or interact with the storage anymore.

image

main

await Firebase.initializeApp(
  name: 'example',
  options: DefaultFirebaseOptions.currentPlatform,
);

usage (the options are initialised by flutterfire)

final itemUploads = FirebaseStorage.instanceFor(bucket: "item-uploads");
print(await itemUploads.ref('item-uploads/raw').listAll());
  1. It worked before the upgrade
  2. The rules look like this
    
    rules_version = '2';

service firebase.storage { match /b/{bucket}/o { match /{allPaths=} { allow read, write: if true; } match /users/{userId}/{allPaths=} { allow read: if request.auth.uid == userId; allow write: if request.auth.uid == userId; } } }

3. Trying the local emulator also fails identically
4. There's no docs for the "unknown" error and I can't find any docs on how to view the server responses
5. I tried reading the source code, but the code-base is rather unknown to me
6. There's no `setLogLevel` on `FirebaseStorage`, so I can't bump the logs
7. The only result online is [this SO question](https://stackoverflow.com/questions/70052479/firebase-storage-an-unknown-error-occurred-please-check-the-error-payload-for) which says I should check my storage rules (I have)
8. I've tried both without and with authentication
9. I've double-checked that some Firebase service accounts (that it worked with before) still are permitted on the bucket
10. The GCP logs don't contain any information, neither do the local emulator logs (perhaps connection problem, or some binding problem?)

### Expected behavior

If the error message says to check the server response, it should also contain the server response to be checked. Or at the very least, if it's "hard" to pass that from the iOS library, it should log it from the iOS library.

### Sample project

Sorry

---

### Flutter doctor

Run `flutter doctor` and paste the output below

<details><summary>Click To Expand</summary>

❯ flutter doctor -v [✓] Flutter (Channel stable, 3.16.1, on macOS 14.0 23A344 darwin-arm64, locale en-SE) • Flutter version 3.16.1 on channel stable at /opt/homebrew/Caskroom/flutter/3.16.1/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7f20e5d18c (3 days ago), 2023-11-27 09:47:30 -0800 • Engine revision 22b600f240 • Dart version 3.2.1 • DevTools version 2.28.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/h/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/h/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A507 • CocoaPods version 1.14.3

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Community Edition (version 2022.2.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.84.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.76.0

[✓] Connected device (4 available) • Alpha (mobile) • 00008130-001C395A2EA0001C • ios • iOS 17.1.1 21B91 • Rialto (mobile) • 00008101-000119410E63001E • ios • iOS 17.0.3 21A360 • macOS (desktop) • macos • darwin-arm64 • macOS 14.0 23A344 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.159

[✓] Network resources • All expected network resources are available.

• No issues found!


</details>

---

### Flutter dependencies

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

<details><summary>Click To Expand</summary>

Dart SDK 3.2.1 Flutter SDK 3.16.1 example 1.0.0+1

dependencies:

dev dependencies:

transitive dependencies:


</details>

---

This downgraded set of deps works:

cloud_firestore: Using Firebase SDK version '10.16.0' defined in 'firebase_core' firebase_auth: Using Firebase SDK version '10.16.0' defined in 'firebase_core' firebase_core: Using Firebase SDK version '10.16.0' defined in 'firebase_core' firebase_dynamic_links: Using Firebase SDK version '10.16.0' defined in 'firebase_core' firebase_storage: Using Firebase SDK version '10.16.0' defined in 'firebase_core' Downloading dependencies Installing AppAuth (1.6.2) Installing BoringSSL-GRPC (0.0.24) Installing Firebase (10.16.0) Installing FirebaseAppCheckInterop (10.18.0) Installing FirebaseAuth (10.16.0) Installing FirebaseAuthInterop (10.18.0) Installing FirebaseCore (10.16.0) Installing FirebaseCoreExtension (10.18.0) Installing FirebaseCoreInternal (10.18.0) Installing FirebaseDynamicLinks (10.16.0) Installing FirebaseFirestore (10.16.0) Installing FirebaseStorage (10.16.0) Installing Flutter (1.0.0) Installing GTMAppAuth (2.0.0) Installing GTMSessionFetcher (3.2.0) Installing GoogleSignIn (7.0.0) Installing GoogleUtilities (7.12.0) Installing PromisesObjC (2.3.1) Installing RecaptchaInterop (100.0.0) Installing abseil (1.20220623.0) Installing camera_avfoundation (0.0.1) Installing cloud_firestore (4.12.2) Installing desktop_webview_auth (0.0.1) Installing firebase_auth (4.12.1) Installing firebase_core (2.21.0) Installing firebase_dynamic_links (5.4.3) Installing firebase_storage (11.4.0) Installing gRPC-C++ (1.49.1) Installing gRPC-Core (1.49.1) Installing google_sign_in_ios (0.0.1) Installing leveldb-library (1.22.2) Installing nanopb (2.30909.1) Installing video_player_avfoundation (0.0.1)

darshankawar commented 11 months ago

Thanks for the report @haf I tried with the plugin example by running on iOS simulator with latest versions pointing to latest Firebase iOS sdk (10.18.0) and by using below code snippet as you shared:

await FirebaseStorage.instance.useStorageEmulator(emulatorHost, 9199);

  final Reference storageRef = FirebaseStorage.instanceFor(bucket: 'triage-79c7c.appspot.com').ref().child('IMG_0101.JPG');
  print(await storageRef.listAll());
  final str = await storageRef.getDownloadURL();
  print(str);

With which I get below:

2023-11-30 17:24:56.302542+0530 Runner[19722:236908] flutter: Instance of 'ListResult'
2023-11-30 17:24:56.989771+0530 Runner[19722:236908] flutter: https://firebasestorage.googleapis.com/v0/b/triage-79c7c.appspot.com/o/IMG_0101.JPG?alt=media&token=4d281f50-7a86-4480-a72e-acac5e80b044

although it doesn't come back with proper result for storageRef.listAll(), it isn't throwing the same error as reported. Can you take a look at the same example and check with your local config to see if you still get same error or not ?

haf commented 11 months ago

Hi @darshankawar thanks for looking into it.

Yes, I get the error I reported; perhaps you could share how I can expose the required debug information to move this forward? As it's obviously behaving differently on your and my systems?

darshankawar commented 11 months ago

@haf Are you specifying a different storage bucket or is that the default one ? If different, then there was a recent fix made related to it https://github.com/firebase/flutterfire/issues/11808#issuecomment-1799039296 that you can check to see if it helps in your case or not.

Couple of things also that you can try:

  1. With 10.18.0, a fresh flutter project + firebase integration to check if the error still persists.
  2. clear up the pub cache or update pod repo

If above doesn't work, can you try by running through XCode and check if you get same error or not ?

haf commented 11 months ago

It looks like this

  final itemUploads = FirebaseStorage.instanceFor(bucket: "item-uploads");
  final log = Logger("saveMediaV2.upload");
  final digest = sha256.convert(bytes);
  final hashName = digest.toString();
  final ext = thumbnail.type == MediaType.image ? 'jpg' : 'mp4';
  final suffix = size == ImageUploadSize.original ? '' : '-1024';
  final uploadFileName = '$hashName$suffix.$ext';
  final uploadRef = itemUploads.ref('item-uploads/raw/$uploadFileName');

  // handling resizing
  final payload = maybeResize(bytes, size);

  log.info('Starting upload of $uploadFileName in size=$size len=${payload.lengthInBytes}...');

  try {
    final uploadTask = uploadRef.putData(
      payload,
      SettableMetadata(
        contentType: thumbnail.type == MediaType.image ? 'image/jpeg' : 'video/mp4',
      ),
    );

I've already tried a complete cache rebuild and the update of the pod repo.

Even if the error doesn't persist in a clean repo, it doesn't help me, as I have an app to build, and then I need to have my own code present. I'd be happy to debug further if I can coerce the library to give me more output?

darshankawar commented 11 months ago

Thanks for the update. As I am unable to replicate the reported behavior, keeping the issue open for team's input.

Lyokone commented 11 months ago

Hey @haf, without any way of reproducing the issue, we can only assume it's a configuration issue. Can you try to run flutterfire CLI again using the latest dev release?

dart pub global activate flutterfire_cli 0.3.0-dev.18 --overwrite
flutterfire configure
haf commented 10 months ago

Hey, thanks for the extra suggestion to try a dev build. I will try this in a few months when I'm forced to upgrade to the latest broken versions, I think. I don't see how it can be a configuration issue since I'm not configuring anything in particular; just adding the packages. IMO all software packages should be able to log enough detail so they can be debugged; especially (!) if I have a debugger I can attach. It's easy to blame the user. Thanks for your help.