0

I'm using gcs bucket for wordpress (wp-stateless plugin) after create and upload media file to a bucket. I copy it to other bucket (duplicate). But generation number of each object has been change (maybe random).

My question is: How to keep generation number same bucket source like in destination bucket? generation number of object

Thanks in advance.

1 Answers1

1

Basically, there’s not an official way of keeping the same version and generation numbers when copying files from one bucket to another. This is WAI and intuitive because the version number refers to this object (which resides on this bucket), when you copy it to another bucket, it's not the same object (it's a copy) so it cannot keep the same version number.

I could think of a workaround, keeping somewhere your own version of the objects and then through the API make an organized copy. This would mean you would be dumping the bucket but you would need to have a list of all the objects and its versions and then add them in sequential order (sounds like a lot of work). You could keep your own versioning (or the same versioning) in the metadata of each object.

I would recommend that if your application depends on the object’s versioning, to use custom metadata. Basically, if you did your own versioning using custom metadata, when copying the objects to a new bucket, it would keep the same metadata.

There is already a feature request created about this. But, it has mentioned that it's currently infeasible.

However, you can raise a new feature request here

Roopa M
  • 2,171
  • 4
  • 12
  • I don't really understand your workaround solution. Could you share API document for copying object that keeping same generation number?. I'm using wp-stateless plugin, but when copy from bucket to other than It's not working as same. – Trần Văn Kiên Mar 26 '22 at 12:36
  • What I mentioned is keeping the **same generation number is currently infeasible** in google cloud. Because Google made this field with its own [purpose](https://cloud.google.com/storage/docs/generations-preconditions#_Generations), it's not the same as a user-made "versioning" metadata attribute. If you build your system to rely on an internal mechanic that isn't designed to do what you want it to do, then chances are that you will run into issues later on. A workaround is instead of using generation number to use a version attribute in the object metadata instead. – Roopa M Mar 28 '22 at 05:36