How to rename an object in Google Storage bucket?

2019-08-06 10:12发布

问题:

How to rename an object in Google Storage bucket through the API?

See also An error attempting to rename a Google Bucket object (Google bug?)

回答1:

Objects can't be renamed. The best you can do is copy to a new object and delete the original. If the new and old object are the same location (which will be true if they're in the same bucket, for example) it will be a metadata-only (no byte copying) operation, and hence fast. However, since it's two operations it won't be atomic.



回答2:

First, use the "rewrite" method to produce a copy of the original object. Then, delete the original object.

Documentation on rewrite: https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite