我正在尝试将图像上传到firebase存储,并将该图像URL用作firestore中的元数据,但图像URL始终为null。 (我假设在我将它添加到我的firestore时图像还没有完成上传)。
Future<File> getPic() async {
return picture = await ImagePicker.pickImage(source:
ImageSource.camera);
}
Future<Uri> uploadPic(File image) async {
StorageReference reference = _storage.ref().child("images/");
StorageUploadTask uploadTask = reference.putFile(image);
Uri location = (await uploadTask.onComplete).uploadSessionUri;
print('img location $location');
return location;
}
floatingActionButton: FloatingActionButton(
onPressed: () {
getPic().then((f) async => await uploadPic(f));
}),
每当我尝试将此图像uri保存到firestore时,它始终为null。那么这里的问题是什么?
尝试
String downloadUrl =
await (await uploadTask.onComplete).ref.getDownloadURL();
而不是你的
Uri location = (await uploadTask.onComplete).uploadSessionUri;
根据firebase的文档
UploadSessionUri
用于恢复在大约的范围内上传相同的文件。周Here is the link for docs