Zen*_*nko 2 firebase flutter firebase-storage flutter-web
抱歉这个菜鸟问题。但是如何从 Uri 获取 Url 字符串?根据我的理解,Url 是 Uri 的子集,但我找不到任何类似.getUrl. 我错过了什么吗?
背景:Flutter Web 中的 FirebaseStorage 以某种方式返回
而不是.getDownloadURL()UriString
来自 Flutter Web 的 FirebaseStorage 包的解释:
Future<Uri> getDownloadURL() 包:firebase/src/storage.dart
返回此引用的长期下载 URL。
getDownloadURL来自Flutter App 的FirebaseStorage 包的解释:
Future<String> getDownloadURL() 包:firebase_storage/firebase_storage.dart
获取该对象的长期下载 URL。
在 Flutter 应用程序中我的 pubspec.yaml:
firebase_core: ^0.5.1
firebase_auth: ^0.18.2
cloud_firestore: ^0.14.2
firebase_storage: ^5.0.0-dev.4
Run Code Online (Sandbox Code Playgroud)
在 Flutter Web 中我的 pubspec.yaml:
firebase: ^7.3.2
cloud_firestore: ^0.14.2
cloud_functions: ^0.6.0+1
Run Code Online (Sandbox Code Playgroud)
我尝试寻找解决方案并阅读文档,但没有找到任何有关将 Uri 从 Firebase 存储getDownloadURL方法转换为 Url 的文章。似乎几乎被视为同一件事。但这给了我错误。参见下面的代码:
*** 代码:
Future<String> uploadImage(String localFilename, String filename, String path, StorageReference ref) async {
final byteData = await rootBundle.load('assets/posts_images/$localFilename');
final bytes = byteData.buffer.asUint8List();
final metadata = UploadMetadata(contentType: 'image/jpeg');
final uploadTask = ref.child('$path/$filename').put(bytes, metadata);
final snapshot = await uploadTask.future;
final url = await snapshot.ref.getDownloadURL();
return url; // Error: A value of type 'Uri' can't be returned from method 'uploadImage' because it has a return type of 'Future<String>'
}
Run Code Online (Sandbox Code Playgroud)
谢谢
Dou*_*son 10
根据文档,Uri类有一个方法toString()。
return url.toString();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5054 次 |
| 最近记录: |