【发布时间】:2021-04-03 04:21:43
【问题描述】:
我正在使用最新的firebase_storage 版本,现在更新了一些存储方法和引用ploadTask.onComplete 不支持。
那么如何获取上传的 pdf url?
一段代码:
Future<String> uploadPdfToStorage(File pdfFile) async {
try {
Reference ref = FirebaseStorage.instance.ref().child('pdfs/${DateTime.now().millisecondsSinceEpoch}');
UploadTask uploadTask = ref.putFile(pdfFile, SettableMetadata(contentType: 'pdf'));
String downloadUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
final String url = await downloadUrl;
print("url:$url");
return url;
} catch (e) {
return null;
}
}
【问题讨论】:
-
你现在的代码有什么问题?如果有错误消息,您应该将其添加到问题中。
标签: firebase flutter dart firebase-storage