flutter - 如何在 Flutter 中从 Firebase 存储中删除文件
问题描述
我尝试了这篇文章中的示例How to delete a Firebase Storage file with flutter?
但它没有用。这是我尝试过的:
String filePath = 'https://firebasestorage.googleapis.com/v0/b/amct-47348.appspot.com/o/ClassificadoImages%2F1579839318515.jpg?alt=media&token=cd8880eb-8b37-45e4-8dc1-e75de0c5f7cb'
.replaceAll(new RegExp(r 'https://firebasestorage.googleapis.com/v0/b/amct-47348.appspot.com/o/ClassificadoImages%2F'), '').split('?')[0];
FirebaseStorage.instance.ref().child(filePath).delete()
.then((_) {
print('Successfully deleted $filePath storage item');
}).catchError((e) {
print("err: $e");
});
这就是它返回的内容:
I / flutter(4920): err: PlatformException(deletion_error, Object does not exist at location., null)
可以对它返回错误的原因提出一些想法,因为它与示例完全相同。谢谢阅读。
解决方案
Firebase SDK 采用存储它们的存储桶中文件的路径。他们不采用 URL 或拆分 URL。它们也不采用 url 编码的字符串。路径必须是用于上传它们的纯字符串。
只是一个猜测,但如果你有以开头的下载 URL
那么文件的字符串路径大概就是
分类图像/1579839318515.jpg
这就是您应该传递的内容FirebaseStorage.instance.ref().child()
以构建使用它的引用(因为 %2F 是 URL 中正斜杠的编码版本)。
推荐阅读
- javascript - 将选择字段值和文本字段值连接到一个文本字段中
- sql-server - SQL 大型插入事务日志已满错误
- spring-mvc - 如何使用 spring mvc 连接 red5Pro 服务器
- mongodb - 在 2 个数据中心场景中设置 Active-Active mongo 的最佳方法?
- apache-flink - flink 流式维护窗口中特定事件的状态
- kubernetes - 警戒线和污点和容忍之间的区别(污点效应-NoExecute)
- javascript - 获取输入图像 Javascript 的尺寸
- javascript - 运行 cypress 测试时,令牌集被删除
- sql - 如何编写一个与第一列结果相关的查询?
- javascript - 如何获取浏览器的缩放级别