upload large video files to storage service

Hey all,

I am developing an app that would include video upload functionality. My storage is Firebase Storage. Everything is working as it should as long as the video files are small enough. I am having challenges when user is uploading large video files.
When using the regular built in Flutterflow action of 'Upload Media to Firebase', the system just hangs.
So, I split the process to two built in FlutterFlow actions of Store Media for Upload, and then Upload media to Firebase, that did not help. system still hangs/crashes.

So, I wrote my own custom action. Code below and was able to improve performance to files of about 150Mb.

I tried creating a Stream Controller for Firebase but reading firebase API documentation, it seems that Firebase Storage does not support putStream but rather only putData for my use case (app). Below is the stream controller code that splits the data to chunks. I had to change to putData which obviously defeats the purpose of stream manager...

Below is the custom Action that is working better than the built in FlutterFlow, but still hangs at the 175Mb upload file size mark..

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/backend/schema/enums/enums.dart';
import '/actions/actions.dart' as action_blocks;
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:path_provider/path_provider.dart';
import 'dart:io';
import 'package:firebase_storage/firebase_storage.dart';
import '../../auth/firebase_auth/auth_util.dart';
import 'dart:async';

Future<String> uploadFileToFirebase(FFUploadedFile? fileBytesReceived) async {
  if (fileBytesReceived == null) {
    return Future.error("File bytes received is null");
  }

  print(
      "Starting upload. File size: ${fileBytesReceived.bytes!.length} bytes.");

  try {
    // Generating a unique file name for storage
    final String fileName =
        'videos/${DateTime.now().millisecondsSinceEpoch}_${fileBytesReceived.name}';

    String directoryPath = '/users/' + currentUserUid + '/videouploads';

    print('setting path');
    // Combine the directory path and file name to create the full storage path
    final storagePath = '$directoryPath/$fileName';
    print(storagePath);

    // Reference to Firebase Storage bucket
    final storageRef = FirebaseStorage.instance.ref().child(storagePath);

    // Create a new upload task
    UploadTask uploadTask = storageRef.putData(
      fileBytesReceived.bytes!,
      SettableMetadata(contentType: 'video/mp4'),
    );

    // Await completion of the upload task
    await uploadTask;

    // Once the upload is complete, get the download URL
    final downloadUrl = await storageRef.getDownloadURL();
    return downloadUrl;
  } catch (e) {
    return Future.error("Error uploading file to Firebase Storage: $e");
  }
}

Is there anything I am missing on the firebase Storage side? any ideas?

Anyone has successful experience with large video file uploads?

2
3 replies