Flutter Web putData doesn't Put the Data

Issue

With Flutter Web, Firebase Storage, Getting an XFile from Image_Picker, I am trying to implement the putData method, (which actually executes without errors). A putFile implementation works fine for me for mobile. I need to use putData for Web.

This simplified code executes without errors, and file name, date, etc all populate in Storage, but without the actual file (9 bytes displayed as size).

I get an XFile from Image_Picker. The sample implementation from flutterfire’s storage example also uses XFile and putData here.

  Future<void> _startUpload(XFile file) async {
    firebase_storage.FirebaseStorage _storage = firebase_storage.FirebaseStorage.instance;
    firebase_storage.UploadTask? _uploadTask;
    String filePath = 'filePath';

    final metadata = firebase_storage.SettableMetadata(
      contentType: 'image/jpeg',
    );

    Uint8List bytesFile = await file.readAsBytes();
    final uploadTask = _storage.ref().child(filePath).putData(bytesFile, metadata);
    final snapshot = await uploadTask;
    final url = await snapshot.ref.getDownloadURL();
    debugPrint('here is the download url: $url');
  }

Solution

Just going to leave this here for future users who encounter this until the bug is fixed. The XFile method fromData isn’t functioning properly as detailed here.

This was my issue. If you use cross_file or image_picker with a crop utility that required you to get an Xfile.fromData, it will fail until this is updated.

Answered By – jbryanh

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *