我在 Flutter 中使用 Firebase 存储。如果上传操作因任何原因失败(例如超过控制台中设置的大小限制),它会导致 StorageException。
我想做这样的事情:
try {
final uploadTask = ref.putFile(docFile);
taskSnapshot = await uploadTask.onComplete;
} on StorageException catch (err) {
// Do something
}
但是没有任何 StorageException
类型,我找不到捕获所有异常的方法。有什么想法吗?
最佳答案
您可以改为执行以下操作。
import 'package:firebase_core/firebase_core.dart' as firebase_core;
try {
final uploadTask = ref.putFile(docFile);
taskSnapshot = await uploadTask.onComplete;
} on firebase_core.FirebaseException catch(e) {
if (e.code == 'permission-denied') {
/// Real permisssion-denied handling
print('User does not have permission to upload to this reference.');
}
if (e.code == 'the-error-code-printed-to-console') {
///the-error-code-printed-to-console handling
print('printing what you want');
}
}
这会处理错误并检查是否需要许可。如果您正在寻找其他原因,您可以先将 e.code
打印到控制台,复制代码并检查之前从控制台复制的代码是否等于 e.code
.
https://stackoverflow.com/questions/63730786/
相关文章:
node.js - 在 node.js 中将字符串转换为 64 位 float
python - 如何一次对每一行进行不同的 tensorflow 张量切片?
python-3.x - SendGrid 无法向 Yahoo 和 Outlook 发送列表-取消订
json - 使用 JSON Body on Rule 调用 REST API Business C
ios - iPhone 上的 Safari 是否支持为 <input type =“file
authentication - 如何在 ReactJS 中实现登录亚马逊?