我尝试了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)
可以使用一些有关为什么返回错误的想法,因为它与示例完全相同。感谢您的阅读。
答案 0 :(得分:0)
Firebase SDK在存储文件的存储桶中采用文件的路径。他们不使用URL或拆分URL。它们也不会采用url编码的字符串。路径必须是用于上传路径的纯字符串。
这只是一个猜测,但是如果您有以'p'开头的下载网址
那么文件的字符串路径可能是
ClassificadoImages / 1579839318515.jpg
这就是您应该传递给FirebaseStorage.instance.ref().child()
的内容,以建立使用它的引用(因为%2F是URL中正斜杠的编码版本)。
答案 1 :(得分:0)
如果您具有存储在firesbase存储中的图像的网址,则可以使用
中的getReferenceFromUrl 方法。
然后我们可以使用引用将其删除。
FirebaseStorage.instance
.getReferenceFromUrl(imageData)
.then((reference) => reference.delete())
.catchError((e) => print(e));