Skip to content

Make Storage.update() rename an object #2672

Closed

Description

@joaoandremartins

I 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.

Activity

  1. yihanzhen commented on Dec 1, 2017

    @yihanzhen
    Contributor

    @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.

  2. self-assigned this
    on Dec 1, 2017
  3. joaoandremartins commented on Dec 1, 2017

    @joaoandremartins
    Author

    @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.

  4. yihanzhen commented on Dec 1, 2017

    @yihanzhen
    Contributor

    @joaoandremartins Thanks for the feedback. I'll take a further look.

  5. yihanzhen commented on Dec 1, 2017

    @yihanzhen
    Contributor

    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 ?

  6. added
    api: storageIssues related to the Cloud Storage API.
    type: questionRequest for information or clarification. Not an issue.
    on Dec 13, 2017
  7. pongad commented on Jan 22, 2018

    @pongad
    Contributor

    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.

  8. joaoandremartins commented on Jan 22, 2018

    @joaoandremartins
    Author

    I understand that renaming is currently impossible.
    This issue is a feature request to have it implemented eventually -- why are you closing it?

  9. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jan 22, 2018
  10. yihanzhen commented on Jan 22, 2018

    @yihanzhen
    Contributor

    @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.

  11. joaoandremartins commented on Jan 22, 2018

    @joaoandremartins
    Author

    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.

  12. pongad commented on Jan 23, 2018

    @pongad
    Contributor

    @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.

  13. added a commit that references this issue on Mar 9, 2026
    e3003f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions