本文介绍了如何以编程方式重命名Google存储中的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google存储Java客户端.

I have a google-storage java client.

我想重命名云上的文件夹.

I want to rename a folder on the cloud.

有办法吗?

我看到了更新帖子,但我没有确定如何更改名称元数据.

I saw the update post but i'm not sure how to change the name meta data.

这是我的尝试,但我不知道要填写什么"entity",并且没有oac.setName()

here is my try but i don't know what to fill in "entity" and there is no oac.setName()

public void renameDirectory(String oldPath, String newName) throws IOException {

    final Storage gsClient = GCSlientFactory.get(PromptoConfig.s.GCP_PROJECT_ID).getGSClient();
    final URI uri = URI.create(oldPath);

    ObjectAccessControl oac = new ObjectAccessControl();
    oac.setId("newName");

    final Storage.ObjectAccessControls.Update update = gsClient.objectAccessControls().update(BUCKET_NAME, uri.toString().replace("gs://"+BUCKET_NAME+"/", ""), "", oac);
    update.execute();
}

还有:

final Storage gsClient = GCSlientFactory.get(PromptoConfig.s.GCP_PROJECT_ID).getGSClient();
final URI uri = URI.create(oldPath);

ObjectAccessControl oac = new ObjectAccessControl();
oac.set("name", newName);

final Storage.ObjectAccessControls.Update update = gsClient.objectAccessControls().update(BUCKET_NAME, uri.toString().replace("gs://"+BUCKET_NAME+"/", ""), "allUsers", oac);
update.execute();

推荐答案

GCS不支持真正的文件夹-名称空间是平坦的,并且"/"的含义实际上是由客户端(和客户端库)施加的.因此,无法原子地重命名文件夹-您需要重命名每个包含的文件,就像gsutil mv命令一样.您可以通过运行以下命令来查看此信息:

GCS doesn't support true folders -- the namespace is flat, and the meaning of "/" is really imposed by clients (and client libraries). As such, folders can't be renamed atomically - you would need to rename each of the contained files, like what the gsutil mv command does. You can see this by running a command like:

gsutil -d mv gs://my-bucket/folder1 gs://my-bucket/folder2

-d选项将使其输出gsutil进行重命名的请求序列.

The -d option will cause it to output the sequence of requests gsutil generates to do the rename.

这篇关于如何以编程方式重命名Google存储中的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:40