【问题标题】:Firebase Storage takes too long to upload videoFirebase 存储上传视频的时间过长
【发布时间】:2021-06-13 10:58:37
【问题描述】:

这是我在 StackOverflow 中的第一个问题。

我正在尝试将视频上传到 Firebase 存储,但上传文件所需的时间太长。我测试了一个 30MB 的文件,完成 O_O 需要 3-4 分钟,而另一个 100MB 的视频需要 6-7 分钟。

我的互联网连接速度为 50Mb/秒(上传-下载),所以我预计它会更快。

注意:我使用的是最新版本的firebasefile_picker

这是 Flutter 的问题还是我需要做些什么?

  Future selectFile() async {
    final result = await FilePicker.platform.pickFiles(allowMultiple: false);
    if (result == null) return;
    final path = result.files.single.path;
    setState(() => file = File(path));
  }

  Future uploadFile() async {
    if (file == null) return;
    final fileName = basename(file.path);
    final destination = 'files/$fileName';
    task = FirebaseApi.uploadFile(destination, file);
    setState(() {});
    if (task == null) return;
    final snapshot = await task.whenComplete(() {});
    final urlDownload = await snapshot.ref.getDownloadURL();
    await FirebaseFirestore.instance.collection("users").doc(currentUser.uid).update({
      'image1': urlDownload,
    });
  }


class FirebaseApi {
  static UploadTask uploadFile(String destination, File file) {
    try {
      final ref = FirebaseStorage.instance.ref(destination);

      return ref.putFile(file);
    } on FirebaseException catch (e) {
      return null;
    }
  }

提前致谢^_^

【问题讨论】:

  • 我正在使用如下所示的类似代码,大约需要 30 分钟才能完成。有任何想法吗? Future uploadFile({required File file}) async { final fileName = file.uri.pathSegments.last;最终 uuid = Uuid();最终文件路径 = "视频/${uuid.v4()}_$fileName";调试打印(文件路径);最终存储 = FirebaseStorage.instance.ref().child(filePath);最终上传任务 = storage.putFile(file);最终快照 = 等待 uploadTask.whenComplete(() {});最终下载URL = 等待快照.ref.getDownloadURL();返回下载地址; }

标签: firebase flutter google-cloud-storage


【解决方案1】:

我认为是这样的。在我的应用中,上传压缩的 imgae 大约需要 5-6 秒。

您是否曾尝试将视频上传到 WhatsApp 等即时通讯应用?在那里,上传也没有那么快。

(注意:你确定你有 50 mBit/s 的 上传 速度吗?这对我来说似乎很多)

【讨论】:

  • 相同的测试视频在 WhatsApp 或任何其他消息传递应用程序(如 Messenger)中也需要 2-3/秒,是的,我的互联网连接是 50Mb/秒,即使不是:50MB 的视频将永远不要花这么多时间,否则在 WhatsApp 上不会花很短的时间!
猜你喜欢
  • 2019-01-20
  • 2012-12-25
  • 1970-01-01
  • 2021-04-26
  • 1970-01-01
  • 2020-12-10
  • 2020-10-26
  • 1970-01-01
  • 2017-02-25
相关资源
最近更新 更多