我尝试了下面的文章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)
可以使用一些关于为什么返回错误的想法,因为它与示例完全一样。感谢您的阅读。
发布于 2020-01-23 21:50:03
Firebase SDK在存储它们的桶中选择文件的路径。他们不接受URL,也不接受分割URL。他们也不接受url编码的字符串。路径必须是用于上载它们的普通字符串。
只是猜测一下,但是如果您的donwload URL以
那么文件的字符串路径可能是
分类图片/1579839318515.jpg
这就是您应该传递给FirebaseStorage.instance.ref().child()
来构建使用它的引用的内容(因为%2F是URL中正斜杠的编码版本)。
发布于 2020-04-25 18:28:27
如果您拥有存储在firesbase存储库中的映像的url,则可以使用
**StorageReference **中的getReferenceFromUrl
方法。
然后我们可以使用引用删除它。
FirebaseStorage.instance
.getReferenceFromUrl(imageData)
.then((reference) => reference.delete())
.catchError((e) => print(e));
https://stackoverflow.com/questions/59890962
复制相似问题