简体   繁体   English

如何删除文件属性谷歌驱动器

[英]How to delete a file property google drive

I try to delete a file property as follows, but the deletion does not occur.我尝试按如下方式删除文件属性,但没有删除。

            File file = drive.files()
                    .get(fileId)
                    .setFields("properties")
                    .execute();
            Map<String, String> fileProperties = file.getProperties();
            for (Map.Entry<String, String> entry : fileProperties.entrySet()) {
                if (entry.getKey().contains(PermissionTypeEnum.USER.name()) || entry.getKey().contains(PermissionTypeEnum.GROUP.name())
                        || entry.getKey().contains(PermissionTypeEnum.ROLE.name()) || entry.getKey().contains(PermissionTypeEnum.DEPARTMENT.name())) {
                    entry.setValue(null);
                }
            }
            file.setProperties(fileProperties);
            drive.files().update(fileId, file).execute();

How do I delete file properties?如何删除文件属性?

In order to remove a specific property for a file using the Drive API v3, you will have to make use of setAppProperties method.为了使用 Drive API v3 删除文件的特定属性,您必须使用setAppProperties方法。

According to the Java library for Drive API v3 documentation here :根据此处的驱动器 API v3 文档的 Java 库:

setAppProperties > A collection of arbitrary key-value pairs which are private to the requesting app. setAppProperties > 请求应用程序私有的任意键值对的集合。 Entries with null values are cleared in update and copy requests.具有 null 值的条目在更新和复制请求中被清除。

Parameters: appProperties - appProperties or null for none参数: appProperties - appProperties或 null 无

Therefore, you will have to change this line:因此,您将不得不更改此行:

 file.setProperties(fileProperties);

To this:对此:

file.setAppProperties(fileProperties);

Reference参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM