flutter - 无法从 Firebase 存储中获取下载网址
问题描述
我可以成功上传图片,但无法获取上传图片的 URL 另外随着最近方法的变化,我想写一个比这更干净的代码。
try {
await FirebaseStorage.instance
.ref()
.child('user_image')
.child(authResult.user
.uid + //ref gives access to root cloud store , firebase manages all the tokens etc
'.jpg')
.putFile(image);
} on FirebaseException catch (e) {
print(e);
}
//Download the Url
String url = await FirebaseStorage.instance
.ref()
.child('user_image')
.child(authResult.user
.uid + //ref gives access to root cloud store , firebase manages all the tokens etc
'.jpg')
.getDownloadURL();
print('Url' + url);
解决方案
我使用以下代码进行上传和下载。您错过了使用 uploadtask 属性。
final photoRef = FirebaseStorage.instance.ref().child("photos");
UploadTask uploadTask = photoRef.child("$id.jpg").putFile(photo);
String url = await (await uploadTask).ref.getDownloadURL();
推荐阅读
- android - 如何在 LinearLayout 中的另一个视图下移动视图?
- spring-boot - 偏移量的自动提交失败并重试也无法正常工作
- python - Python:Stockfish 正在打开太多进程
- rxjs - 使用 debounceTime 时,observable 延迟了多长时间?
- react-native - 如何以编程方式设置子视图,而不是在 React Native 中使用标记?
- reactjs - 选择多个复选框而不切换
- reactjs - 使用两个不同的 prop 接口 React TypeScript 组件
- java - maven 的哪个插件更适合管理发布版本?
- javascript - 谷歌地图地理编码器以法语返回加拿大的响应,而我需要英语的响应
- java - WebDriverException:等待驱动程序服务器以 phantomjs 启动时超时