I need to be able to rename a file in Cloud Storage using Go on App Engine.
From what I understand from the docs, I should be able to update an object's attributes using
storage.UpdateAttrs. I've tried to do this with something like the following:
attribs := storage.ObjectAttrs{Name: "ShorterFileName.png"}
newObject, err := storage.UpdateAttrs(ctx, oldObject.Bucket, oldObject.Name, attribs)
However, I can't seem to get this to work. Every time I try use it, I get the following type of error:
googleapi: Error 400: Value 'ShorterFileName.png' in content does not agree with value '20150718/L2FwcGhvc3RpbmdfZXVyb3BlL2Jsb2JzL0FFbkIyVXJGQ0RTVGlRMGFad0VMQWIzaHBQWFM1YnpDVC1SRzBJbzRQTG9BTHJNM1djcl9maXhhTFNleTNOMXJiME04RktyUm5nb2R2Mlp2OTJCbC1XLWRYVGYyNlppbkVBLnkzZ1BDVmYxOVY2VHlhdng'. This can happen when a value set through a parameter is inconsistent with a value set in the request., invalidParameter
I can rename the file by copying the existing file and then deleting the old one, but this takes close to a second, which is far longer than I would imagine it would take to simply update the object attributes.
So, what am I doing wrong with storage.ObjectAttrs? Is there a more efficient way to rename an object?