首页 > 解决方案 > 从上传的文件中获取 DownloadURL

问题描述

我想知道getDownloadURL()当我上传文件时如何获取。我想上传一个文件并获取该文件的downloadURL,然后将其存储到数据库中。你能举例说明如何在一个函数中做到这一点吗?

标签: flutterdartfirebase-storage

解决方案


String filePath = "videoTitle.mp4";
    StorageReference ref = FirebaseStorage.instance.ref().child(filePath);
    StorageUploadTask uploadTask =
        ref.putFile(video, StorageMetadata(contentType: "video/mp4"));


    await uploadTask.onComplete;
    if (uploadTask.isComplete) {
      String downloadUrl = await ref.getDownloadURL();
      return downloadUrl;
    }

推荐阅读