Renaming a file in cloud storage

275 views
Skip to first unread message

John Beckett

unread,
Jul 18, 2015, 4:20:40 AM7/18/15
to google-ap...@googlegroups.com
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?

Glenn Lewis

unread,
Jul 18, 2015, 10:16:26 AM7/18/15
to John Beckett, google-appengine-go
Hmmm... it looks to me like the Go Veneer storage client library is broken for file renaming.  I apologize for that... it looks like I never fully tested the rename functionality.  :-(
In the meantime, I'm going to see if I can get rename working with the google.golang.org/api/storage/v1 API directly (and then update the first library).
I'll get back to the list when I get it working... it might not be until Monday, looking at the calendar.
-- Glenn

--
You received this message because you are subscribed to the Google Groups "google-appengine-go" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Beckett

unread,
Jul 18, 2015, 10:54:02 AM7/18/15
to google-ap...@googlegroups.com, jgbe...@gmail.com
Thanks for the update Glenn.  I can easily wait for next week, and in the mean time, I'll just use the copy + delete method to get things working.

~ John

Glenn Lewis

unread,
Jul 18, 2015, 11:47:34 AM7/18/15
to John Beckett, google-appengine-go
Thanks, John.  I've filed an issue: https://github.com/google/google-api-go-client/issues/88
-- Glenn

Glenn Lewis

unread,
Jul 19, 2015, 8:40:04 PM7/19/15
to John Beckett, google-appengine-go
I just got a reply from a Cloud Storage engineer that the API has no "rename" capability and the best thing to do is copy+delete.
I'll update the issue.  Maybe it would be nice to provide a "Rename" method in the client library to avoid future confusion.
-- Glenn
Reply all
Reply to author
Forward
0 new messages