Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_storage]: The operation couldn’t be completed. Message too long #16999

Open
1 task done
feinstein opened this issue Jan 21, 2025 · 11 comments
Open
1 task done
Labels
Needs Attention This issue needs maintainer attention. platform: ios Issues / PRs which are specifically for iOS. plugin: storage type: bug Something isn't working

Comments

@feinstein
Copy link
Contributor

feinstein commented Jan 21, 2025

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Storage

Which platforms are affected?

iOS

Description

I am using an iOS simulator and when I try to upload a picture, I am getting this error:

[firebase_storage/unknown] The operation couldn’t be completed. Message too long

Reproducing the issue

Try running this code in an iOS Simulator with iOS 18.2:

import 'dart:io';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:path/path.dart' as path;
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:pic_uploader/firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  await FirebaseAuth.instance.signInAnonymously();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool isUploading = false;
  final ImagePicker _picker = ImagePicker();
  final FirebaseStorage _storage = FirebaseStorage.instance;
  final FirebaseFirestore _firestore = FirebaseFirestore.instance;
  late final imagesStream = _firestore.collection('users').doc(FirebaseAuth.instance.currentUser?.uid ?? '').collection('images').orderBy('uploadedAt', descending: true).snapshots();

  Future<void> _uploadImages() async {
    try {
      final List<XFile> images = await _picker.pickMultiImage();

      for (var image in images) {
        final String fileName = path.basename(image.path);
        final userId = FirebaseAuth.instance.currentUser?.uid ?? '';

        // Create storage reference
        final storageRef = _storage.ref().child('users/$userId/images/$fileName');

        // Upload image
        setState(() => isUploading = true);
        await storageRef.putFile(File(image.path));

        // Get download URL
        final downloadUrl = await storageRef.getDownloadURL();

        // Save to Firestore
        await _firestore.collection('users').doc(userId).collection('images').add({
          'imageUrl': downloadUrl,
          'fileName': fileName,
          'uploadedAt': FieldValue.serverTimestamp(),
          'version': 1,
        });
      }
    } finally {
      setState(() => isUploading = false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          ElevatedButton(
            onPressed: _uploadImages,
            child: const Text('Upload Images'),
          ),
          if (isUploading) const CircularProgressIndicator(),
          Expanded(
            child: StreamBuilder<QuerySnapshot>(
              stream: imagesStream,
              builder: (context, snapshot) {
                if (!snapshot.hasData) return const CircularProgressIndicator();

                return GridView.builder(
                  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3,
                    crossAxisSpacing: 4,
                    mainAxisSpacing: 4,
                  ),
                  itemCount: snapshot.data!.docs.length,
                  itemBuilder: (context, index) {
                    final data = snapshot.data!.docs[index].data() as Map<String, dynamic>;
                    return Image.network(
                      data['imageUrl'],
                      loadingBuilder: (context, child, progress) {
                        if (progress == null) {
                          return child;
                        }
                        return Center(
                          child: CircularProgressIndicator(
                            value: progress.expectedTotalBytes != null ? progress.cumulativeBytesLoaded / progress.expectedTotalBytes! : null,
                          ),
                        );
                      },
                      fit: BoxFit.cover,
                    );
                  },
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}

Firebase Core version

3.10.1

Flutter Version

3.24.4

Relevant Log Output

[firebase_storage/unknown] The operation couldn’t be completed. Message too long

Flutter dependencies

Expand Flutter dependencies snippet
Dart SDK 3.5.4
Flutter SDK 3.24.4
pic_uploader 1.0.0+1

dependencies:
- cloud_firestore 5.6.2 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cupertino_icons 1.0.8
- firebase_auth 5.4.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 3.10.1 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_storage 12.4.1 [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 sky_engine]
- image_picker 1.1.2 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_linux image_picker_macos image_picker_platform_interface image_picker_windows]
- path 1.9.0

dev dependencies:
- flutter_lints 4.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]

transitive dependencies:
- _flutterfire_internals 1.3.50 [collection firebase_core firebase_core_platform_interface flutter meta]
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- characters 1.3.0
- clock 1.1.1
- cloud_firestore_platform_interface 6.6.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 4.4.2 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins]
- collection 1.18.0
- cross_file 0.3.4+2 [meta web]
- fake_async 1.3.1 [clock collection]
- file_selector_linux 0.9.3+2 [cross_file file_selector_platform_interface flutter]
- file_selector_macos 0.9.4+2 [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+3 [cross_file file_selector_platform_interface flutter]
- firebase_auth_platform_interface 7.5.1 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.13.7 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web]
- firebase_core_platform_interface 5.4.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.19.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_storage_platform_interface 5.2.1 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.10.8 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http meta web]
- flutter_plugin_android_lifecycle 2.0.24 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- http 1.3.0 [async http_parser meta web]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.12+20 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 3.0.6 [flutter flutter_web_plugins image_picker_platform_interface mime web]
- image_picker_ios 0.8.12+2 [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.10.1 [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]
- leak_tracker 10.0.5 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.5 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 4.0.0
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- meta 1.15.0
- mime 2.0.0
- plugin_platform_interface 2.1.8 [meta]
- sky_engine 0.0.99
- source_span 1.10.0 [collection path term_glyph]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.2 [async]
- string_scanner 1.2.0 [source_span]
- term_glyph 1.2.1
- test_api 0.7.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- typed_data 1.4.0 [collection]
- vector_math 2.1.4
- vm_service 14.2.5
- web 1.1.0

Additional context and comments

No response

@feinstein feinstein added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Jan 21, 2025
@SelaseKay SelaseKay added plugin: storage platform: ios Issues / PRs which are specifically for iOS. labels Jan 22, 2025
@SelaseKay
Copy link
Contributor

Hi @feinstein, I couldn't reproduce this issue on my end. Could you review the firebase_storage example to check if there’s anything you might have missed?

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 22, 2025
@feinstein
Copy link
Contributor Author

Hi @SelaseKay I tried to copy-paste the example main inside my main, so it would use my firebase configurations, but I am getting another error now:

Image

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 22, 2025
@feinstein
Copy link
Contributor Author

@SelaseKay btw, I am not the first one to report this #12973

@SelaseKay
Copy link
Contributor

Hi @feinstein, could you try commenting out the following block and testing again?

  if (defaultTargetPlatform != TargetPlatform.windows) {
    // window currently don't support storage emulator
    final emulatorHost =
        (!kIsWeb && defaultTargetPlatform == TargetPlatform.android)
            ? '10.0.2.2'
            : 'localhost';

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

The OP of the linked issue confirmed that an update resolved the problem on their end, so it seems the issue has been addressed.

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 22, 2025
@feinstein
Copy link
Contributor Author

I removed that section and I get the original error

Image

And I am already on the latest version 12.4.1

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 22, 2025
@SelaseKay
Copy link
Contributor

I'm unable to reproduce on my end. Have you tried testing on an actual iOS device?

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 22, 2025
@feinstein
Copy link
Contributor Author

feinstein commented Jan 22, 2025

No I didn't, I don't have one. Are you using the iOS image gallery picker? The file path it gives me is:

flutter: /Users/michelfeinstein/Library/Developer/CoreSimulator/Devices/553B8096-3723-4092-B2F1-222776238EB8/data/Containers/Data/Application/AE1A417A-0BF2-4C67-9123-D17E834275E4/tmp/image_picker_AF55D77F-DB74-4A41-9455-349822708D38-94428-00000B21D71C95FB.jpg

Do you get something similar? Could it be a path that's too long? If it is, then I don't know how to solve this bc the temp folder is also very long... maybe in a real device its shorter.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 22, 2025
@SelaseKay
Copy link
Contributor

Hi @feinstein, my path looks very similar and works fine for me, so I doubt that's the issue. This might be caused by something upstream. Could you try switching networks and testing again? Alternatively, waiting a bit and retrying later might help. It seems to be related to this issue.

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 22, 2025
@feinstein
Copy link
Contributor Author

I don't think that's the case because I have tried this on different days, multiple times and the error message doesn't seem to be network related. Can you escalate this to an engineer that knows what this message means?

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 22, 2025
@SelaseKay
Copy link
Contributor

Hi @feinstein, this issue doesn't appear to be directly related to FlutterFire and might be originating from the native side. It could be worth testing on other iOS devices. This issue thread seems related, and I recommend trying the solutions suggested in this comment to see if they resolve the issue.

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 23, 2025
@feinstein
Copy link
Contributor Author

Interesting, looking at that issue, it seems like some iphones have different sizes of datagrams, so if the firebase sdk is trying to upload a file and each datagram is bugger than what's supported, it's going to fail.

I am using an iPhone 16 with ios 18.2 simulador if you want to test.

Now, from that issue they say that changing from InLineDataPart to FileDataPart solved it, but this is at the native sdk level, so I can't fix it myself, the Flutter sdk needs to change how it's sending data to the underlying ios native SDK.

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Attention This issue needs maintainer attention. platform: ios Issues / PRs which are specifically for iOS. plugin: storage type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants