在我的 Flutter 应用程序中,我正在尝试将图像上传到 Firebase 存储,然后获取 URL。图像正在上传,我可以在 Web 界面中看到它,但是当我在有效引用上调用 getDownloadUrl() 时(我可以使用调试器看到相对路径),我得到type 'NoSuchMethodError' is not a subtype of type 'Exception'
并且实际错误发生在method_channel_reference.dart
其中出于某种原因, wherestorage
为 null 并因此storage.app
引发错误。
@override
Future<String /*!*/ > getDownloadURL() async {
try {
Map<String, dynamic> data = await MethodChannelFirebaseStorage.channel
.invokeMapMethod<String, dynamic>(
'Reference#getDownloadURL', <String, dynamic>{
'appName': storage.app.name,
'maxOperationRetryTime': storage.maxOperationRetryTime,
'maxUploadRetryTime': storage.maxUploadRetryTime,
'maxDownloadRetryTime': storage.maxDownloadRetryTime,
'bucket': storage.bucket,
'path': fullPath,
});
return data['downloadURL'];
} catch (e) {
throw convertPlatformException(e);
}
}
上传代码是这样的:
final uploadTask = _firebaseStorage.ref().child(storagePath).putFile(recipeImage);
try {
await uploadTask.whenComplete(() {});
final url = await uploadTask.snapshot.ref.getDownloadURL();
return right<RecipeFailure, String>(url);
} catch (e) {
return left<RecipeFailure, String>(RecipeFailure.imageUploadFailed());
}
我正在使用
firebase_core: ^0.7.0
firebase_auth: ^0.20.0+1
firebase_storage: ^7.0.0
cloud_firestore: ^0.16.0
我尝试清理、重建和降级依赖项。在这一点上,我不知道在哪里看。我想问题是存储实例被删除或根本没有初始化,但为什么上传工作呢?欢迎任何帮助。