【问题标题】:how to get the path of Asset picked from gallery multi_image_picker2?如何从图库 multi_image_picker2 中获取 Asset 的路径?
【发布时间】:2022-01-19 10:11:36
【问题描述】:

我正在使用 multi_image_picker2: ^5.0.2。我只需要将选定的图像上传到 Firebase。我怎样才能得到 List 的路径?当我使用 image.name 时,我遇到了问题:

'file.absolute.existsSync()': 不正确。

.

代码是:

  var images = <Asset>[].obs;
  await FirebaseStorage.instance
        .ref('products/$docID')
        .putFile(File(images[0].name??""));

【问题讨论】:

  • 您好,您的问题解决了吗?
  • 我已经使用这个库将资产转换为文件flutter_absolute_path: git: url: https://github.com/kornperkus/flutter_absolute_path.git
  • 如果它对您有用,那么您可以将其作为答案发布,并提供更多解释,以便对社区有所帮助。

标签: flutter google-cloud-firestore image-gallery


【解决方案1】:

您可以使用 pickedFilename.path

var images = <Asset>[].obs;
 var img= await FirebaseStorage.instance
        .ref('products/$docID')
        .putFile(File(images[0].name??""));

var imgPath=img.path;

【讨论】:

  • 它没有上传到firestorage,这样做
【解决方案2】:
if (productImage1 != null) {
        final storageReference =
            FirebaseStorage.instance.ref().child("products/imgname");

        final uploadTask = storageReference.putFile(productImage1!);
        final downloadUrl = await uploadTask.whenComplete(() => null);
        imgUrl = await downloadUrl.ref.getDownloadURL();
      }

这里productImage1包含了选择图片后的路径。 productImage1 = imagefile.path;

【讨论】:

    猜你喜欢
    • 2020-06-19
    • 2021-12-03
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多