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

🐛 [firebase_storage] .getdata gives weird url and returns 404 #7688

Closed prggTheProgrammer closed 2 years ago

prggTheProgrammer commented 2 years ago

Bug report

.getdata fails when I call the .getdata method on a .ref() it doesn't stop loading, but gives no error in the flutter console. But if I click inspect in google it says: failed to load resource: https://firebasestorage.googleapis.com/v0/b/%5Bobject%20Object%5D/o/<filename> the server responded with a status of 404 () So I think the problem is that it is not getting the url right, because this is not a good url and returns 404. The only way I get it to work is to use the whole e.g. .ref("gs://storage_name/file"), but that is not what is mentioned in the docs (https://firebase.flutter.dev/docs/storage/usage#downloading-files) and this doesn't work on mobile.

Steps to reproduce

Steps to reproduce the behavior:

  1. Setup your flutter project for chrome
  2. add firebase_storage to pubspec.yaml
  3. run this program:
    
    import 'package:firebase_core/firebase_core.dart';
    import 'package:firebase_storage/firebase_storage.dart';

void main() async{ await Firebase.initializeApp(); var t = await FirebaseStorage.instance.ref("filepath").getData(); print(t.toString()); }

4. inspect in chrome and see the 404 in console
5. And if you change the filepath to the full path, it should work and you should get a list of bytes

### Expected behavior

It should print a list of bytes just like it happens when you do the whole path. If I am supposed to put the whole path, then how do I do it on mobile and then please update the docs

### Sample project

see steps above

---

### Flutter doctor

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

[√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.19042.1415], locale nl-NL) [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [√] Chrome - develop for the web [√] Android Studio (version 2020.3) [√] Connected device (2 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 2.15.1 Flutter SDK 2.8.1 schoolstrijd 1.0.0+1

dependencies:

dev dependencies:

transitive dependencies:


prggTheProgrammer commented 2 years ago

Update: It now gives this error: Error: [firebasestorage/object-not-found] No object exists at the desired reference. at Object.throw [as throw] (http://localhost:62317/dart_sdk.js:5063:11) at http://localhost:62317/packages/firebase_core/src/internals.dart.lib.js:81:63 at _RootZone.runUnary (http://localhost:62317/dart_sdk.js:40062:59) at _FutureListener.catchError.handleError (http://localhost:62317/dart_sdk.js:34996:33) at handleError (http://localhost:62317/dart_sdk.js:35567:51) at Function._propagateToListeners (http://localhost:62317/dart_sdk.js:35593:17) at _Future.new.[_completeError] (http://localhost:62317/dart_sdk.js:35443:23) at async._AsyncCallbackEntry.new.callback (http://localhost:62317/dart_sdk.js:35479:31) at Object._microtaskLoop (http://localhost:62317/dart_sdk.js:40330:13) at _startMicrotaskLoop (http://localhost:62317/dart_sdk.js:40336:13) at http://localhost:62317/dart_sdk.js:35811:9

darshankawar commented 2 years ago

@prggTheProgrammer I tried the sample code you shared and incorporated in the plugin's official example and ran on web using latest stable, but didn't see the issue you mentioned. Also the chrome console doesn't show any error.

Screenshot 2021-12-28 at 3 55 16 PM

Not sure if I am missing anything to properly replicate it. Can you try the same example and check if you still get same behavior with it too ?

russellwheatley commented 2 years ago

This error code: firebase_storage/object-not-found means there isn't anything at the path you have passed into .ref(<PATH>) I would double check the path is correct, there might be an issue with special characters for example.

google-oss-bot commented 2 years ago

Hey @prggTheProgrammer. 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!

prggTheProgrammer commented 2 years ago

@darshankawar Thanks for testing, I am using the manual installation (https://firebase.flutter.dev/docs/manual-installation/web), mabey it has something to do with that.

@russellwheatley, yes I know, I checked it, it works when I use the whole path (but this doesn't work on mobile) but when I remove the gs://... It doesn't work anymore.

prggTheProgrammer commented 2 years ago

The problem is already fixed but I was using the old sdk () instead of ()