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] [iOS] Uploaded files do not show up in the console #11808

Closed toco1001 closed 1 year ago

toco1001 commented 1 year ago

Bug report

Uploading image fails by using putData method only in iOS in firebase_storage 11.4.1. It works on Android and Web.

And you can avoid this error by using firebase_storage: 11.3.1.

Steps to reproduce

Steps to reproduce the behavior:

  1. Add a package firebase_storage: ^11.4.1 to pubspec.yaml.
  2. Use putData to try to upload image to Firebase Storage.
  3. No image gets uploaded. Can't see the image file in Firebase Storage dashboard.

ADDED:

  1. After uploading, the image url is accessed by token-url (via getDownloadUrl method), BUT can't be opened and previewed by using public url (without token).

Expected behavior

ADDED:

Sample project

Below code is not working in firebase_storage 11.4.1, but working in 11.3.1

static Future<String?> uploadImage({required Uint8List? imageFileBytes}) async {
    // ... rest of the code ...

    try {
      final metadata = SettableMetadata(contentType: 'image/jpeg');
      await ref.putData(imageFileBytes, metadata);
      print('[DEBUG] Succeeded to upload image!');
      // ... rest of the code ...

    } on FirebaseException catch (e) {
      print('[DEBUG] Failed to uploadImage: error: $e');
      return null;
    }
  }

Additional context

↓Firebase Storage Rule for my bucket↓

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read: if true;
      allow write: if request.auth != null;
    }
  }
}

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Copy code Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.13.9, on macOS 13.5 22G74 darwin-arm64, locale en-JP) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS (Xcode 15.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.83.1) [✓] Connected device (3 available) [✓] Network resources • No issues found! ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 3.1.5 Flutter SDK 3.13.9 my_flutter_project 1.0.0+1 dependencies: - adaptive_breakpoints 0.1.6 [flutter] - animated_text_kit 4.2.2 [flutter characters] - any_link_preview 3.0.0 [flutter html http shared_preferences string_validator url_launcher] - app_review 2.1.2+1 [http package_info_plus url_launcher flutter] - app_settings 4.2.0 [flutter] - app_tracking_transparency 2.0.4 [flutter] - audioplayers 5.1.0 [audioplayers_android audioplayers_darwin audioplayers_linux audioplayers_platform_interface audioplayers_web audioplayers_windows file flutter http meta path_provider synchronized uuid] - auto_size_text 3.0.0 [flutter] - cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - carousel_slider 4.2.1 [flutter] - clear_all_notifications 0.0.3 [flutter] - cloud_firestore 4.12.2 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 4.5.3 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - cupertino_icons 1.0.5 - dual_screen 1.0.4 [flutter] - easy_debounce 2.0.3 - file_picker 5.5.0 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32] - firebase_analytics 10.6.2 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.12.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.21.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_crashlytics 3.4.2 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_database 10.3.2 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter] - firebase_dynamic_links 5.4.2 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface] - firebase_instance_id 1.0.0 [flutter] - firebase_messaging 14.7.2 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_remote_config 4.3.2 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - firebase_storage 11.3.1 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - fl_chart 0.63.0 [equatable flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - flutter_app_badger 1.5.0 [flutter] - flutter_image_compress 2.0.3 [flutter flutter_image_compress_platform_interface flutter_image_compress_common flutter_image_compress_web] - flutter_image_compress_web 0.1.3+1 [flutter flutter_web_plugins flutter_image_compress_platform_interface js] - flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml] - flutter_linkify 6.0.0 [flutter linkify] - flutter_local_notifications 14.1.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math web] - flutter_native_splash 2.2.19 [args flutter flutter_web_plugins js html image meta path universal_io xml yaml] - flutter_picker 2.1.0 [flutter] - flutter_signin_button 2.0.0 [flutter font_awesome_flutter] - flutter_slidable 3.0.0 [flutter] - gallery_saver 2.3.2 [flutter path_provider http path] - google_mobile_ads 3.0.0 [meta flutter visibility_detector webview_flutter_android webview_flutter_wkwebview webview_flutter] - google_sign_in 6.1.4 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - http 0.13.6 [async http_parser meta] - image_gallery_saver 2.0.3 [flutter] - in_app_purchase 3.1.7 [flutter in_app_purchase_android in_app_purchase_platform_interface in_app_purchase_storekit] - intl 0.18.1 [clock meta path] - introduction_screen 3.1.8 [flutter dots_indicator collection flutter_keyboard_visibility] - open_store 0.5.0 [flutter url_launcher] - package_info_plus 4.0.2 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - path_provider 2.0.15 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - permission_handler 11.0.1 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - provider 6.0.5 [collection flutter nested] - recase 4.1.0 - seo 0.0.4 [flutter rxdart] - share 2.0.4 [meta mime flutter] - share_plus 7.1.0 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi win32] - shared_preferences 2.1.2 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - sign_in_with_apple 5.0.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web] - skeletons 0.0.3 [flutter] - timeago 3.4.0 [intl] - tutorial_coach_mark 1.2.8 [flutter flutter_lints] - twitter_login 4.4.0 [crypto flutter http] - universal_html 2.2.4 [async csslib charcode collection html meta source_span typed_data universal_io] - url_launcher 6.1.11 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_strategy 0.2.0 [flutter_web_plugins] - uuid 3.0.7 [crypto] - video_player 2.6.1 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] - webview_flutter 4.2.2 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview] - window_size 0.1.0 [flutter] dev dependencies: - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] dependency overrides: - package_info_plus 4.0.2 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] transitive dependencies: - _flutterfire_internals 1.3.11 [collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.4.6 [crypto path pointycastle] - args 2.4.2 - async 2.11.0 [collection meta] - audioplayers_android 4.0.1 [audioplayers_platform_interface flutter] - audioplayers_darwin 5.0.1 [audioplayers_platform_interface flutter] - audioplayers_linux 3.0.0 [audioplayers_platform_interface flutter] - audioplayers_platform_interface 6.0.0 [flutter meta plugin_platform_interface] - audioplayers_web 4.0.0 [audioplayers_platform_interface flutter flutter_web_plugins js] - audioplayers_windows 3.0.0 [audioplayers_platform_interface flutter] - boolean_selector 2.1.1 [source_span string_scanner] - cached_network_image_platform_interface 2.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.2 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.3.0 - charcode 1.3.1 - checked_yaml 2.0.3 [json_annotation source_span yaml] - cli_util 0.4.0 [meta path] - clock 1.1.1 - cloud_firestore_platform_interface 6.0.3 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.8.3 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.5.6 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.6.6 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.17.2 - convert 3.1.1 [typed_data] - cross_file 0.3.3+4 [js meta] - crypto 3.0.3 [typed_data] - csslib 0.17.3 [source_span] - dbus 0.7.8 [args ffi meta xml] - dots_indicator 2.1.2 [flutter] - equatable 2.0.5 [collection meta] - fake_async 1.3.1 [clock collection] - ffi 2.0.2 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.7.4 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.5+4 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 7.0.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.8.5 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta] - firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.8.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics_platform_interface 3.6.10 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_database_platform_interface 0.2.5+10 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_database_web 0.2.3+10 [firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins js] - firebase_dynamic_links_platform_interface 0.2.6+10 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.5.11 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.11 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_remote_config_platform_interface 1.4.10 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.4.10 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js] - firebase_storage_platform_interface 4.4.9 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.6.10 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_blurhash 0.7.0 [flutter] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_image_compress_common 1.0.1 [flutter flutter_image_compress_platform_interface] - flutter_image_compress_platform_interface 1.0.2 [flutter plugin_platform_interface cross_file] - flutter_keyboard_visibility 5.4.1 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_linux flutter_keyboard_visibility_macos flutter_keyboard_visibility_web flutter_keyboard_visibility_windows flutter] - flutter_keyboard_visibility_linux 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_keyboard_visibility_macos 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface] - flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter] - flutter_keyboard_visibility_windows 1.0.0 [flutter_keyboard_visibility_platform_interface flutter] - flutter_local_notifications_linux 4.0.0+1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories] - flutter_local_notifications_platform_interface 7.0.0+1 [flutter plugin_platform_interface] - flutter_plugin_android_lifecycle 2.0.15 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - font_awesome_flutter 9.2.0 [flutter] - google_identity_services_web 0.2.1 [js meta] - google_sign_in_android 6.1.16 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.6.2 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.4.1 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.12.0+2 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js] - html 0.15.4 [csslib source_span] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.1.3 [archive meta xml] - in_app_purchase_android 0.3.0+5 [collection flutter in_app_purchase_platform_interface json_annotation] - in_app_purchase_platform_interface 1.3.4 [flutter plugin_platform_interface] - in_app_purchase_storekit 0.3.6+4 [collection flutter in_app_purchase_platform_interface json_annotation] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - linkify 5.0.0 - lints 2.0.1 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.9.1 - mime 1.0.4 - nested 1.0.0 [flutter] - octo_image 1.0.2 [flutter flutter_blurhash] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.3 - path_provider_android 2.0.27 [flutter path_provider_platform_interface] - path_provider_foundation 2.2.3 [flutter path_provider_platform_interface] - path_provider_linux 2.1.11 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.6 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.7 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler_android 11.1.0 [flutter permission_handler_platform_interface] - permission_handler_apple 9.1.4 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.12.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.3 [flutter permission_handler_platform_interface] - petitparser 5.1.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.4 [meta] - pointycastle 3.7.3 [collection convert js] - process 4.2.4 [file path platform] - quiver 3.2.1 [matcher] - rxdart 0.27.7 - share_plus_platform_interface 3.3.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid] - shared_preferences_android 2.1.4 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.2.2 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.2.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.2.0 [flutter plugin_platform_interface] - shared_preferences_web 2.1.0 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.2.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sign_in_with_apple_platform_interface 1.0.0 [flutter plugin_platform_interface meta] - sign_in_with_apple_web 1.0.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface js] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - sqflite 2.2.8+4 [flutter sqflite_common path] - sqflite_common 2.4.5+1 [synchronized path meta] - stack_trace 1.11.0 [path] - stream_channel 2.1.1 [async] - string_scanner 1.2.0 [source_span] - string_validator 0.3.0 - synchronized 3.1.0 - term_glyph 1.2.1 - test_api 0.6.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - timezone 0.9.2 [path] - typed_data 1.3.2 [collection] - universal_io 2.2.2 [collection meta typed_data] - url_launcher_android 6.0.35 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.4 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.5 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.5 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface] - url_launcher_web 2.0.17 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.6 [flutter url_launcher_platform_interface] - vector_math 2.1.4 - video_player_android 2.4.9 [flutter video_player_platform_interface] - video_player_avfoundation 2.4.6 [flutter video_player_platform_interface] - video_player_platform_interface 6.1.0 [flutter plugin_platform_interface] - video_player_web 2.0.16 [flutter flutter_web_plugins video_player_platform_interface] - visibility_detector 0.3.3 [flutter] - web 0.1.4-beta - webview_flutter_android 3.8.0 [flutter webview_flutter_platform_interface] - webview_flutter_platform_interface 2.3.1 [flutter meta plugin_platform_interface] - webview_flutter_wkwebview 3.5.0 [flutter path webview_flutter_platform_interface] - win32 5.0.6 [ffi] - xdg_directories 0.2.0+3 [meta path process] - xml 6.2.2 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

HatsuneMikuV commented 1 year ago

I have same issue

uploadTask = ref.putFile(file, metadata); 11.4.1 not working,but working in 11.2.8

danagbemava-nc commented 1 year ago

I can reproduce the issue using the plugin example app. It does not seem to be an issue with only putData. I tested with putFile and it reproduced with that method as well. I did not get this issue with android as reported above.

Labeling for further investigation from the team.

cc @russellwheatley

russellwheatley commented 1 year ago

I've just converted an image to bytes and uploaded it successfully via putData() which I can view in Firebase storage console. I am using on my iPhone using iOS 16.6.1.

toco1001 commented 1 year ago

I've just converted an image to bytes and uploaded it successfully via putData() which I can view in Firebase storage console. I am using on my iPhone using iOS 16.6.1.

Thank you for debugging. Could you test it on iOS 17.x as well?

danagbemava-nc commented 1 year ago

I also tested on iOS 17, specifically, iOS 17.1.0. Perhaps that could be the cause of the issue. I don't have any devices lower than iOS 17. I asked @darshankawar to also test on his device, he is running iOS 15.2 and on his device the image showed up in the console so it seems like this is specific to iOS 17

@toco1001, just to confirm, does your upload method throw any errors or is it processed successfully and the image doesn't show up?

toco1001 commented 1 year ago

@toco1001, just to confirm, does your upload method throw any errors or is it processed successfully and the image doesn't show up?

After executing putData, there were no errors and the uploading process was successful, but the image did not display in the console.

HatsuneMikuV commented 1 year ago

I tested on version 16.6.1 and found that the problematic firebase_storage version is 11.4.1. I'm using firebase_storage 11.2.8 and 11.3.1 with no problems. But the 11.4.1 upload is successful, but the console cannot find the image.

danagbemava-nc commented 1 year ago

Hi @toco1001 @HatsuneMikuV, can you try reaching out to firebase support to see if there's anything they can do? Considering the upload is successful but the image does not show up on the console, this seems like it is an issue with the console

russellwheatley commented 1 year ago

@toco1001 - Are you specifying a different Storage bucket? I think I know what the problem is if that is the case.

toco1001 commented 1 year ago

No, I'm not. I'm specifying correct Storage bucket.

static Future<String?> uploadUserProfileImage({
    required Uint8List? imageFileBytes,
  }) async {
    final currentUserId = CurrentUserContext.currentUserId;
    if (currentUserId == null) {
      return null;
    }
    if (imageFileBytes == null) {
      print(
          '[DEBUG] FirebaseStorageService: uploadUserProfileImage: error: no imageFile');
      return null;
    }

    //This `uuid` is required to reflect the image immediately after uploading.
    final uuid = const Uuid().v4(); 
    final storageRef = FirebaseStorage.instanceFor(
        bucket: 'my-bucket-user-profile-images');
    final ref = storageRef.ref('$currentUserId/$uuid.jpeg');
    try {
      final metadata = SettableMetadata(contentType: 'image/jpeg');
      await ref.putData(imageFileBytes, metadata);
      print(
          '[DEBUG] FirebaseStorageService: uploadUserProfileImage: success to upload image!');
      final uploadedUserImageUrl =
          "https://storage.googleapis.com/my-bucket-user-profile-images/$currentUserId/$uuid.jpeg";
      return uploadedUserImageUrl;
    } on FirebaseException catch (e) {
      print(
          '[DEBUG] FirebaseStorageService: uploadUserProfileImage: error: $e');
      return null;
    }
  }
toco1001 commented 1 year ago

Hi @toco1001 @HatsuneMikuV, can you try reaching out to firebase support to see if there's anything they can do? Considering the upload is successful but the image does not show up on the console, this seems like it is an issue with the console

OK. I'll contact Firebase support. But please keep in mind that this is working fine with 11.3.1 and lower versions.

russellwheatley commented 1 year ago

@toco1001 - is this the default storage bucket? my-bucket-user-profile-images. If it is not the default storage bucket (which it doesn't appear to be), then I think I have the solution to your issue.

toco1001 commented 1 year ago

@russellwheatley my-bucket-user-profile-images is not the default storage bucket. It's used only for managing user profile images.

russellwheatley commented 1 year ago

My PR ought to fix your issue: https://github.com/firebase/flutterfire/pull/11844