1
votes

I have been working on an app with flutter where the user takes a series of photos and the app generates a time lapse of the photos (or video). I generate an mp4 video using platform channels, however, when uploading the mp4 to firebase storage the video uploads as empty. I can verify the mp4 was written correctly because I can view the video on my laptop that the emulator writes.

Has anyone came across this error before?

Below is the code for uploading to firebase storage:

  Future saveMp4(File mp4File, User user, String date) async {
    StorageReference ref = firestorage
        .ref()
        .child(user.uid)
        .child("videos")
        .child(date+'.mp4');
    print (mp4File);
    StorageUploadTask uploadTask = ref.putFile(mp4File, StorageMetadata(contentType: 'video/mp4'));
    await uploadTask.onComplete;
    String downloadUrl = await ref.getDownloadURL();
    print ("download url: $downloadUrl");
  }

Here is the output of the upload event with the location of the File that contains the video.

flutter: File: '/Users/ryanmorris/Library/Developer/CoreSimulator/Devices/9A6FB4BC-90B2-4AF4-A622-841979AD5430/data/Containers/Data/Application/554FDF1E-0793-47DA-964A-AF661D46CEA1/Documents/export.mp4'
flutter: EVENT StorageTaskEventType.progress
flutter: EVENT StorageTaskEventType.resume
flutter: EVENT StorageTaskEventType.progress
    [C33.1 8D504A8D-BFFF-468C-8970-17985062A8CB 192.168.1.22:62408<->172.217.23.10:443]
    Connected Path: satisfied (Path is satisfied), interface: en0
    Duration: 1.029s, DNS @0.001s took 0.005s, TCP @0.008s took 0.026s, TLS took 0.052s
    bytes in/out: 3976/1035, packets in/out: 10/8, rtt: 0.043s, retransmitted packets: 0, out-of-order packets: 0
flutter: EVENT StorageTaskEventType.progress
flutter: EVENT StorageTaskEventType.success

On the IOS platform side I used the code from https://github.com/cameronehrlich/CEMovieMaker. I don't believe the issue is with the platform code because I can play the output video fine.

Here is my flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.9.4, on Mac OS X 10.14.1 18B50c, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.2)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
[✓] Android Studio (version 3.1)
[✓] Connected devices (1 available)

The firebase_storage version is 1.0.3.

Thank you for your help!

1
Video uploads as empty - you Mean uploaded video file to Storage Duration is Zero .? - or it Show the Exact file size but don't play. ? - anmol.majhail
@anmol.majhail The uploaded video file to Storage is zero bytes - Swooshftw
Having the same problem. Any updates? - Jonas

1 Answers

1
votes

Make sure when you are creating a file in temp folder the writeAsBytes operation is an async you must wait or execute upload to firestorage in .then((File f){..})