Firebase存储中的文件夹不会被删除? [英] Folder in Firebase storage does not get deleted?

查看:127
本文介绍了Firebase存储中的文件夹不会被删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除Firebase存储中的文件夹中的内容:

I am trying to delete content within a folder in firebase storage:

我尝试通过以下功能来做到这一点:

I attempt to do so with the following function:

            let storageRef = Storage.storage().reference().child((Auth.auth().currentUser?.uid)!).child("post:\(selectedPost.media[0].postID!)/")
//        let postRef = storageRef.child("image.png")

        // Delete the file
        storageRef.delete { error in
            if error != nil {
                // Uh-oh, an error occurred!
                print("FAIL DELETING POST FROM STORAGE")
            } else {
                // File deleted successfully
                print("SUCCESS DELETING STORAGE REF TO POST!")
            }
        }

问题在于它不这样做.它显示失败:

The problem is that it does not do that. It prints that it has failed:

    Optional(Error Domain=FIRStorageErrorDomain Code=-13010 "Object LWzvQXAoX3Ov9DW9LopWFFjJBJY2/post:579755726 does not exist." UserInfo={object=LWzvQXAoX3Ov9DW9LopWFFjJBJY2/post:579755726, ResponseBody={
  "error": {
    "code": 404,
    "message": "Not Found.  Could not delete object",
    "status": "DELETE_OBJECT"
  }
}

当检查存储时,我可以清楚地看到该文件夹​​确实存在.

When checking in the storage I can clearly see that that folder does exist.

怎么了?

推荐答案

Firestore客户端SDK不提供删除整个文件夹的操作.

Firestore client SDKs don't offer an operation to delete an entire folder.

实际上,Cloud Storage中实际上没有任何文件夹".仅有对象名称,看起来像它们包含文件夹.这只是为了帮助您组织内容,因此您不必在控制台中查看整个文件列表.

In actuality, there are not actually any "folders" in Cloud Storage. There are just object names that look like they contain folders. This is just to help you organize your content so you don't have to see the entire list of files in the console.

您要做的是将文件的所有名称存储在其他位置,例如数据库,然后在需要删除它们时查询数据库以获取名称.或者,您可以使用gsutil手动删除整个文件集.在SDK提供列表API允许您使用通用前缀列出对象之前,您将无法通过移动客户端执行此操作. Firebase团队正在努力解决这个问题,但目前没有时间表.

What you'll want to do is store all the names of the files somewhere else, such as a database, then query the database to get the names when it's time to delete them. Or you can delete the entire set of files manually with gsutil. You won't be able to do this from the mobile client until the SDKs offer a list API that let you list object with a common prefix. The Firebase team is working on this, but there is no timeline right now.

这篇关于Firebase存储中的文件夹不会被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆