如何从 Firebase 存储文件中获取 url?
How to get the url from Firebase Storage file?
我想从 firebase 存储中检索 URL 的 Uint8List 图像。但我不能那样做。它打印快照,而不是 url。请帮忙
我的代码:
void _storeSignature() async {
try {
final Uint8List? signature = await exportSignature();
final FirebaseStorage? storage = FirebaseStorage.instance;
final String? pictureUrl =
"signature/${DateTime.now().millisecondsSinceEpoch.toString()}.png";
final ref = storage!.ref().child(pictureUrl!);
final uploadTask = ref.putData(signature!);
final downurl = await uploadTask.whenComplete(() {
return ref.getDownloadURL();
});
final url = downurl.toString();
print(url);
} catch (e) {
rethrow;
}
}
调用 ref.getDownloadURL()
时,URL 必须 await
改变
return ref.getDownloadURL();
进入
return await ref.getDownloadURL();
UploadTask
class 扩展了 Future
,因此您也可以在那里使用 await
:
await ref.putData(signature!);
final downurl = await ref.getDownloadURL();
final url = downurl.toString();
我想从 firebase 存储中检索 URL 的 Uint8List 图像。但我不能那样做。它打印快照,而不是 url。请帮忙
我的代码:
void _storeSignature() async {
try {
final Uint8List? signature = await exportSignature();
final FirebaseStorage? storage = FirebaseStorage.instance;
final String? pictureUrl =
"signature/${DateTime.now().millisecondsSinceEpoch.toString()}.png";
final ref = storage!.ref().child(pictureUrl!);
final uploadTask = ref.putData(signature!);
final downurl = await uploadTask.whenComplete(() {
return ref.getDownloadURL();
});
final url = downurl.toString();
print(url);
} catch (e) {
rethrow;
}
}
调用 ref.getDownloadURL()
时,URL 必须await
改变
return ref.getDownloadURL();
进入
return await ref.getDownloadURL();
UploadTask
class 扩展了 Future
,因此您也可以在那里使用 await
:
await ref.putData(signature!);
final downurl = await ref.getDownloadURL();
final url = downurl.toString();