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.73k stars 3.98k forks source link

[firebase_storage]: putData fails with [firebase_storage/object-not-found] No object exists at the desired reference.??? #13805

Closed ChurikiTenna closed 3 weeks ago

ChurikiTenna commented 3 weeks ago

Is there an existing issue for this?

Which plugins are affected?

Storage

Which platforms are affected?

iOS

Description

This code fails with [firebase_storage/object-not-found] No object exists at the desired reference. error.

try {
      debugPrint('FirebaseStorageUtil upload: $path');
      FirebaseStorage storage = FirebaseStorage.instance;
      Reference ref = storage.ref().child(path);
      TaskSnapshot snapshot = await ref.putFile(file);
      debugPrint('snapshot.state: ${snapshot.state}');
    } catch (e) {
      debugPrint('Upload Error: $e');
      rethrow;
    }

It's just trying to put a file to storage. No object should exist in the reference.

Then, I uploaded a dummy image to the storage from the console, and tried the code.

スクリーンショット 2024-11-07 19 58 53

which also failed with the same error:

flutter: FirebaseStorageUtil upload: images/15D982CE-942C-458B-BB77-E1471224BE87/image.png
flutter: Upload Error: [firebase_storage/object-not-found] No object exists at the desired reference.

Storage rule:

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

Reproducing the issue

Try the code.

Future<String?> pickImageFromLibrary(ImageSource source) async {
    try {
      final image = await picker.pickImage(
          source: source, imageQuality: 50, maxHeight: 1200, maxWidth: 1200);
      // 画像がnullの場合戻る
      if (image == null) return null;
      final imageTemp = File(image.path);
      // ファイルアップロード
      var url = await FirebaseStorageUtil.shared.upload(
          "images/${LocalStorage.userUUID.getString()}/${DateTime.now().toIso8601String()}",
          imageTemp);
      return url;
    } catch (e) {
      debugPrint('Failed to pick image: $e');
      rethrow;
    }
  }

class FirebaseStorageUtil {
  static final shared = FirebaseStorageUtil();

  Future<String> upload(String path, File file) async {
    try {
      debugPrint('FirebaseStorageUtil upload: $path');
      FirebaseStorage storage = FirebaseStorage.instance;
      Reference ref = storage.ref().child(path);
      TaskSnapshot snapshot = await ref.putFile(file);
      debugPrint('snapshot.state: ${snapshot.state}');
      return '';
    } catch (e) {
      debugPrint('Upload Error: $e');
      rethrow;
    }
  }
}

Firebase Core version

3.2.0

Flutter Version

3.4.3

Relevant Log Output

flutter: FirebaseStorageUtil upload: images/15D982CE-942C-458B-BB77-E1471224BE87/2024-11-07T19:54:03.718426
flutter: Upload Error: [firebase_storage/object-not-found] No object exists at the desired reference.

Flutter dependencies

Expand Flutter dependencies snippet
```yaml Replace this line with the contents of your `flutter pub deps -- --style=compact`. ```

Additional context and comments

No response

ChurikiTenna commented 3 weeks ago

I needed replace GoogleService-Info.plist to the latest version. I guess it was accessing to a wrong bucket??