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.63k stars 3.95k forks source link

πŸ› [Firebase_storage] download urls are missing token #12247

Closed thunderbug1 closed 6 months ago

thunderbug1 commented 7 months ago

Bug report

I am trying to generate download urls for images in flutter web based on a filename.

This is the flutter code:

final String filePath = 'userContent/$userId/profilePics/thumbnails/$modifiedFilename';
final Reference ref = FirebaseStorage.instance.ref().child(filePath);
final downloadUrl = await ref.getDownloadURL();
print("downloadUrl: $downloadUrl");

This is an example url that the code produces: https://firebasestorage.googleapis.com/v0/b/activilitng.appspot.com/o/userContent%2F5sXkJ8Y7N4an8OR0EipdEYrx0e03%2FprofilePics%2Fthumbnails%2Fmotoki-tonn-G1BGJNYnfzI-unsplash_100x100.avif

This is the url that the firebase console gives me for the same file: https://firebasestorage.googleapis.com/v0/b/activilitng.appspot.com/o/userContent%2F5sXkJ8Y7N4an8OR0EipdEYrx0e03%2FprofilePics%2Fthumbnails%2Fmotoki-tonn-G1BGJNYnfzI-unsplash_100x100.avif?alt=media&token=891bb31e-9df1-418d-a467-0ff544eb1d68

As you can see the query parameters are missing and the browser gives a "permission denied" error without them

Steps to reproduce

Steps to reproduce the behavior:

  1. Setup a firebase project and upload an image
  2. use the code from above to create a download url
  3. See error

Expected behavior

The url returned from ref.getDownloadURL(); should come with query parameters (alt and token)

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, 3.16.9, on Ubuntu 22.04.3 LTS 5.15.133.1-microsoft-standard-WSL2, locale en_US.UTF-8) [βœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [βœ—] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [βœ“] Linux toolchain - develop for Linux desktop [!] Android Studio (not installed) [βœ“] Connected device (1 available) [βœ“] Network resources ! Doctor found issues in 2 categories. ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 3.2.6 Flutter SDK 3.16.9 activilit 0.0.1+1 dependencies: - async 2.11.0 [collection meta] - badges 3.1.2 [flutter] - cached_network_image 3.3.1 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image] - cloud_firestore 4.14.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_functions 4.6.0 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - cream_of_the_crop 0.92.1 [flutter flutter_web_plugins plugin_platform_interface] - crop_image 1.0.11 [flutter] - cupertino_icons 1.0.6 - enum_to_string 2.0.1 - equatable 2.0.5 [collection meta] - firebase_app_check 0.2.1+8 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.16.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.24.2 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.7.10 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_storage 11.6.0 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - flutter_app_badger 1.5.0 [flutter] - flutter_avif 2.3.0 [flutter flutter_avif_platform_interface flutter_avif_android flutter_avif_ios flutter_avif_macos flutter_avif_linux flutter_avif_windows flutter_avif_web] - flutter_dotenv 5.1.0 [flutter] - flutter_lints 3.0.1 [lints] - flutter_map_cancellable_tile_provider 1.0.0 [dio flutter flutter_map] - flutter_oss_licenses 2.0.1 [path meta yaml dart_pubspec_licenses args] - flutter_riverpod 2.4.9 [collection flutter meta riverpod state_notifier] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - flutter_widget_from_html 0.14.11 [flutter flutter_widget_from_html_core fwfh_cached_network_image fwfh_chewie fwfh_just_audio fwfh_svg fwfh_url_launcher fwfh_webview html] - font_awesome_flutter 10.6.0 [flutter] - geoflutterfire_plus 0.0.20 [cloud_firestore flutter rxdart] - geolocator 10.1.0 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows] - go_router 12.1.3 [collection flutter flutter_web_plugins logging meta] - google_fonts 6.1.0 [flutter http path_provider crypto] - google_sign_in 6.2.1 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - http 1.2.0 [async http_parser meta web] - image_compression_flutter 1.0.3 [flutter flutter_web_plugins cross_file flutter_image_compress image_compression] - image_cropper 5.0.1 [flutter image_cropper_platform_interface image_cropper_for_web] - image_cropper_for_web 3.0.0 [flutter flutter_web_plugins image_cropper_platform_interface js] - image_picker 1.0.7 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows] - image_size_getter 2.1.2 [collection hashcodes] - intl 0.18.1 [clock meta path] - introduction_screen 3.1.12 [flutter collection dots_indicator flutter_keyboard_visibility] - location_picker_flutter_map 2.1.0 [flutter flutter_map geolocator http intl latlong2 url_launcher flutter_map_location_marker flutter_map_cancellable_tile_provider] - mailto 2.0.0 - maptiler_flutter 0.1.0 [http] - overlay_support 2.1.0 [flutter async] - package_info_plus 4.2.0 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - page_view_indicators 2.0.0 [flutter] - platform_detect 2.0.11 [meta pub_semver] - pwa_install 0.0.5 [flutter js] - qr_flutter 4.1.0 [flutter qr] - reorderable_grid 1.0.10 [flutter] - rxdart 0.27.7 - sentry_flutter 7.14.0 [flutter flutter_web_plugins sentry package_info_plus meta ffi] - settings_ui 2.0.2 [flutter] - share_plus 7.2.1 [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] - url_launcher 6.2.3 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - video_player 2.8.2 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] - video_player_web 2.1.3 [flutter flutter_web_plugins video_player_platform_interface] dev dependencies: - 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] transitive dependencies: - _flutterfire_internals 1.3.16 [collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.4.10 [crypto path pointycastle] - args 2.4.2 - audio_session 0.1.18 [flutter flutter_web_plugins rxdart meta] - boolean_selector 2.1.1 [source_span string_scanner] - build_cli_annotations 2.1.0 [args meta] - cached_network_image_platform_interface 4.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.1.1 [cached_network_image_platform_interface flutter flutter_cache_manager] - characters 1.3.0 - chewie 1.7.4 [cupertino_icons flutter provider video_player wakelock_plus] - clock 1.1.1 - cloud_firestore_platform_interface 6.1.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.9.0 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions_platform_interface 5.5.11 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.6.11 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.18.0 - convert 3.1.1 [typed_data] - cross_file 0.3.3+8 [meta web] - crypto 3.0.3 [typed_data] - csslib 1.0.0 [source_span] - dart_pubspec_licenses 2.0.2 [yaml path json_annotation] - dbus 0.7.10 [args ffi meta xml] - dio 5.4.0 [async http_parser meta path] - dots_indicator 2.1.2 [flutter] - fake_async 1.3.1 [clock collection] - ffi 2.1.0 - file 7.0.0 [meta path] - file_selector_linux 0.9.2+1 [cross_file file_selector_platform_interface flutter] - file_selector_macos 0.9.3+3 [cross_file file_selector_platform_interface flutter] - file_selector_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface] - file_selector_windows 0.9.3+1 [cross_file file_selector_platform_interface flutter] - firebase_app_check_platform_interface 0.1.0+10 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_app_check_web 0.1.0+10 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 7.0.9 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.8.13 [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.10.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging_platform_interface 4.5.18 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.18 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_storage_platform_interface 5.1.3 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.6.17 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - fixnum 1.1.0 - flutter_avif_android 2.3.0 [flutter flutter_avif_platform_interface] - flutter_avif_ios 2.3.0 [flutter flutter_avif_platform_interface] - flutter_avif_linux 2.3.0 [flutter flutter_avif_platform_interface] - flutter_avif_macos 2.3.0 [flutter flutter_avif_platform_interface] - flutter_avif_platform_interface 2.3.0 [ffi flutter flutter_rust_bridge meta uuid] - flutter_avif_web 2.3.0 [flutter flutter_web_plugins flutter_avif_platform_interface js flutter_rust_bridge] - flutter_avif_windows 2.3.0 [flutter flutter_avif_platform_interface] - flutter_cache_manager 3.3.1 [clock collection file flutter http path path_provider rxdart sqflite uuid] - flutter_compass 0.8.0 [flutter] - flutter_image_compress 1.1.3 [flutter] - 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_map 6.1.0 [async collection flutter http latlong2 logger meta polylabel proj4dart vector_math] - flutter_map_location_marker 8.0.3 [flutter flutter_compass flutter_lints flutter_map geolocator latlong2] - flutter_plugin_android_lifecycle 2.0.17 [flutter] - flutter_rust_bridge 1.82.3 [args build_cli_annotations js meta path puppeteer shelf shelf_static shelf_web_socket uuid web_socket_channel yaml tuple] - flutter_svg 2.0.9 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - flutter_widget_from_html_core 0.14.11 [csslib flutter html logging] - fwfh_cached_network_image 0.14.2 [cached_network_image flutter flutter_cache_manager flutter_widget_from_html_core] - fwfh_chewie 0.14.7 [chewie flutter flutter_widget_from_html_core video_player] - fwfh_just_audio 0.14.2 [flutter flutter_widget_from_html_core just_audio] - fwfh_svg 0.8.1 [flutter flutter_svg flutter_widget_from_html_core] - fwfh_url_launcher 0.9.0+4 [flutter flutter_widget_from_html_core url_launcher] - fwfh_webview 0.14.8 [flutter flutter_widget_from_html_core logging webview_flutter webview_flutter_android webview_flutter_wkwebview] - geolocator_android 4.4.0 [flutter geolocator_platform_interface uuid] - geolocator_apple 2.3.4 [flutter geolocator_platform_interface] - geolocator_platform_interface 4.2.0 [flutter plugin_platform_interface vector_math meta] - geolocator_web 2.2.0 [flutter flutter_web_plugins geolocator_platform_interface] - geolocator_windows 0.2.2 [flutter geolocator_platform_interface] - google_identity_services_web 0.3.0+2 [meta web] - google_sign_in_android 6.1.21 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.7.2 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.4.5 [flutter plugin_platform_interface] - google_sign_in_web 0.12.3+2 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http web] - hashcodes 2.0.0 - html 0.15.4 [csslib source_span] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.1.4 [archive meta xml] - image_compression 1.0.4 [image mime path] - image_cropper_platform_interface 5.0.0 [flutter plugin_platform_interface http] - image_picker_android 0.8.9+3 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 3.0.2 [flutter flutter_web_plugins image_picker_platform_interface mime] - image_picker_ios 0.8.9 [flutter image_picker_platform_interface] - image_picker_linux 0.2.1+1 [file_selector_linux file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_macos 0.2.1+1 [file_selector_macos file_selector_platform_interface flutter image_picker_platform_interface] - image_picker_platform_interface 2.9.3 [cross_file flutter http plugin_platform_interface] - image_picker_windows 0.2.1+1 [file_selector_platform_interface file_selector_windows flutter image_picker_platform_interface] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - just_audio 0.9.36 [just_audio_platform_interface just_audio_web audio_session rxdart path path_provider async uuid crypto meta flutter] - just_audio_platform_interface 4.2.2 [flutter plugin_platform_interface] - just_audio_web 0.4.9 [just_audio_platform_interface flutter flutter_web_plugins] - latlong2 0.9.0 [intl] - lints 3.0.0 - lists 1.0.1 [meta] - logger 2.0.2+1 - logging 1.2.0 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.10.0 - mgrs_dart 2.0.0 [unicode] - mime 1.0.4 - nested 1.0.0 [flutter] - octo_image 2.0.0 [flutter] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.3 - path_parsing 1.0.1 [vector_math meta] - path_provider 2.1.2 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.2.2 [flutter path_provider_platform_interface] - path_provider_foundation 2.3.1 [flutter path_provider_platform_interface] - path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface] - path_provider_windows 2.2.1 [ffi flutter path path_provider_platform_interface win32] - petitparser 6.0.2 [meta] - platform 3.1.4 - plugin_platform_interface 2.1.8 [meta] - pointycastle 3.7.3 [collection convert js] - polylabel 1.0.1 [collection] - pool 1.5.1 [async stack_trace] - proj4dart 2.1.0 [mgrs_dart wkt_parser meta] - provider 6.1.1 [collection flutter nested] - pub_semver 2.1.4 [collection meta] - puppeteer 3.6.0 [archive async collection http logging path petitparser pool] - qr 3.0.1 [meta] - riverpod 2.4.9 [meta stack_trace state_notifier] - sentry 7.14.0 [http meta stack_trace uuid] - share_plus_platform_interface 3.3.1 [cross_file flutter meta mime plugin_platform_interface path_provider uuid] - shelf 1.4.1 [async collection http_parser path stack_trace stream_channel] - shelf_static 1.1.2 [convert http_parser mime path shelf] - shelf_web_socket 1.0.4 [shelf stream_channel web_socket_channel] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - sprintf 7.0.0 - sqflite 2.3.0 [flutter sqflite_common path] - sqflite_common 2.5.0+2 [synchronized path meta] - stack_trace 1.11.1 [path] - state_notifier 1.0.0 [meta] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - synchronized 3.1.0+1 - term_glyph 1.2.1 - test_api 0.6.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - tuple 2.0.2 - typed_data 1.3.2 [collection] - unicode 0.3.1 [lists] - url_launcher_android 6.2.2 [flutter url_launcher_platform_interface] - url_launcher_ios 6.2.3 [flutter url_launcher_platform_interface] - url_launcher_linux 3.1.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.1.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.3.1 [flutter plugin_platform_interface] - url_launcher_web 2.2.3 [flutter flutter_web_plugins url_launcher_platform_interface web] - url_launcher_windows 3.1.1 [flutter url_launcher_platform_interface] - uuid 4.3.3 [crypto sprintf meta fixnum] - vector_graphics 1.1.9+2 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.9+2 - vector_graphics_compiler 1.1.9+2 [args meta path_parsing xml vector_graphics_codec path] - vector_math 2.1.4 - video_player_android 2.4.11 [flutter video_player_platform_interface] - video_player_avfoundation 2.5.5 [flutter video_player_platform_interface] - video_player_platform_interface 6.2.2 [flutter plugin_platform_interface] - wakelock_plus 1.1.4 [flutter flutter_web_plugins meta wakelock_plus_platform_interface win32 dbus package_info_plus js] - wakelock_plus_platform_interface 1.1.0 [flutter plugin_platform_interface meta] - web 0.3.0 - web_socket_channel 2.4.0 [async crypto stream_channel] - webview_flutter 4.4.4 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview] - webview_flutter_android 3.13.2 [flutter webview_flutter_platform_interface] - webview_flutter_platform_interface 2.9.1 [flutter meta plugin_platform_interface] - webview_flutter_wkwebview 3.10.1 [flutter path webview_flutter_platform_interface] - win32 5.2.0 [ffi] - wkt_parser 2.0.0 - xdg_directories 1.0.4 [meta path] - xml 6.5.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

darshankawar commented 7 months ago

Thanks for the report @thunderbug1 Can you try with the plugin example and check if using it, you get same behavior as reported ?

gives a "permission denied" error without them

Can you also provide the complete error log ?

thunderbug1 commented 7 months ago

Thanks for the report @thunderbug1 Can you try with the plugin example and check if using it, you get same behavior as reported ?

gives a "permission denied" error without them

Can you also provide the complete error log ?

There isn't really an error log, the http request just returns:

{ "error": { "code": 403, "message": "Permission denied." } }

thunderbug1 commented 7 months ago

I found a workaround that solves the issue for me by making the files public and using google cloud storage links directly instead of firebase links. That, however, is just a workaround and not a solution for this bug.

darshankawar commented 7 months ago

Thanks for the update. Are you using non-default bucket ?

thunderbug1 commented 7 months ago

Thanks for the update. Are you using non-default bucket ?

No, that issue appeared with the default bucket of the project. Haven't tried to access other.

darshankawar commented 7 months ago

Thanks for the update and your patience while we figure this out. I used the code snippet you provided in original description and included it in plugin example, ran on web using latest stable version and observed expected behavior, as below:

  1. Firebase console download url:

https://firebasestorage.googleapis.com/v0/b/triage-79c7c/o/Address_proof_Light_bill.JPG?alt=media&token=d2f3ab0f-af15-4d38-a055-1b88c59262fe

  1. downloadurl received from code:
The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:54899/YeRi8pwOxzE=
downloadUrl: https://firebasestorage.googleapis.com/v0/b/triage-79c7c/o/Address_proof_Light_bill.JPG?alt=media&token=d2f3ab0f-af15-4d38-a055-1b88c59262fe

Both urls have token.

I see that you tried with .avif image file extension and I tried with jpg, not sure if that would make a difference though.

google-oss-bot commented 7 months ago

Hey @thunderbug1. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 6 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@thunderbug1 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.