GeezerVison is showing github.com — Make Storage.update() rename an object · Issue #2672 · googleapis/google-cloud-java
Make Storage.update() rename an object #2672Labels api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.type: questionRequest for information or clarification. Not an issue. DescriptionI expected the following call to rename an object. Unfortunately, its behaviour is not the expected, and it's very different from other similar calls like setMetadata().
Storage gcs = ...;
gcs.update(BlobInfo.newBuilder("existingBucket", "existingObject")
.setBlobId(BlobId.of("existingBucket", "newObject"))
.build());
AFAICT, this tries to make a dummy update to gs://existingBucket/newObject, which fails because the URI doesn't exist.
Logically, the behaviour of this call should be to rename the object, which is what I want to do, and appears to be impossible as per this: gsutil mv copies and removes, which ideally we would avoid doing.
Is there any way to rename a file that doesn't involve copying and removing?
If not, then I'd like to request one. Activityyihanzhen commented on Dec 1, 2017 @joaoandremartins Please refer to this code snippet from the Storage interface to update metadata of a blob:
String bucketName = "my_unique_bucket";
String blobName = "my_blob_name";
String newBlobName = "new_blob_name";
Blob blob = storage.get(bucketName, blobName);
BlobInfo updatedInfo = blob.toBuilder()
.setBlobId(BlobId.of(bucketName, newBlobName))
.build();
storage.update(updatedInfo);
Feel free to repost if that does not solve your problem. joaoandremartins commented on Dec 1, 2017 @hzyi-google thanks for the help.
Unfortunately, that didn't work. I'm still getting a Not found error.
As I mentioned in my report,setBlobId() isn't having the desired effect. This should be looked into. yihanzhen commented on Dec 1, 2017 yihanzhen commented on Dec 1, 2017 It seems that Object#update is only used to update the metadata per here. Therefore additional changes have to be made outside the client library for this request. Can you tell a look as well @neozwu ? pongad commented on Jan 22, 2018 IIUC, Storage objects cannot be "renamed". To rename, you must copy to the new place and delete the original. This doc provides some code samples. joaoandremartins commented on Jan 22, 2018 I understand that renaming is currently impossible.
This issue is a feature request to have it implemented eventually -- why are you closing it? yihanzhen commented on Jan 22, 2018 @joaoandremartins I marked this issue as a feature request and added it to the backlog (Though I believe there is a chance that GCS does not allow renaming objects by design). Comments and discussion are still welcome here. joaoandremartins commented on Jan 22, 2018 Thanks a lot for the explanation @hzyi-google
If it's impossible to rename things by design in GCS, then feel free to do however you like with this issue. Having to pay for operations just to rename an object doesn't feel right, though. pongad commented on Jan 23, 2018 @joaoandremartins I'm sorry I didn't communicate clearly. The Storage API itself provides no way to rename objects. @hzyi-google Thank you for adding this to feature backlog. added a commit that references this issue on Mar 9, 2026This issue will close once commit e3003f4 is merged into the 'main' branch.e3003f4
MetadataMetadataapi: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.type: questionRequest for information or clarification. Not an issue. DevelopmentNo branches or pull requestsIssue actions
|