gpt4 book ai didi

firebase - 如何将图像上传到 firebase 存储中的文件夹中

转载 作者:IT王子 更新时间:2023-10-29 07:02:07 25 4
gpt4 key购买 nike

我正在编写一个应用程序,它可以从图库中选择一张图片并将其上传到 firestore 中的一个文件夹中。

await Future.forEach(_paths.entries, (v) async {
String uid = Uuid().v1();
StorageReference imgReference =
_storageReference.child("Form2").child(uid);
StorageUploadTask task = imgReference.putFile(
File(v.value)
);
StorageTaskSnapshot downloadURL = await
task.onComplete;
String value = await downloadURL.ref.getDownloadURL();
paths[uid] = value;
}

图像没有上传到文件夹中。但是是直接上传到firestore

最佳答案

您必须在 .child() 中指定文件夹名称。喜欢:.child("/$folder").child("$fileName")

示例:

    StorageReference ref = FirebaseStorage.instance.ref().child('/$folder').child(fileName);
StorageUploadTask uploadTask = ref.putData(imageData);
print('Upload triggered in the background.');
...

return await (await uploadTask.onComplete).ref.getDownloadURL();

关于firebase - 如何将图像上传到 firebase 存储中的文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57435335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com