I have a google-storage java client.
I want to rename a folder on the cloud.
It there a way to do it?
I saw the update post but i'm not sure how to change the name meta data.
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();
}
and also:
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 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
The -d option will cause it to output the sequence of requests gsutil generates to do the rename.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With