func ExampleCopyObject() { ctx := Example_auth() o, err := storage.CopyObject(ctx, "bucketname", "file1", "another-bucketname", storage.ObjectAttrs{Name: "file2"}) if err != nil { log.Fatal(err) } log.Println("copied file:", o) }
// copyFile copies a file in Google Cloud Storage. func (d *demo) copyFile(fileName string) { copyName := fileName + "-copy" fmt.Fprintf(d.w, "Copying file /%v/%v to /%v/%v:\n", bucket, fileName, bucket, copyName) attrs := storage.ObjectAttrs{ Name: copyName, ContentType: "text/plain", Metadata: map[string]string{ "x-goog-meta-foo-copy": "foo-copy", "x-goog-meta-bar-copy": "bar-copy", }, } obj, err := storage.CopyObject(d.ctx, bucket, fileName, bucket, attrs) if err != nil { d.errorf("copyFile: unable to copy /%v/%v to bucket %q, file %q: %v", bucket, fileName, bucket, copyName, err) return } d.cleanUp = append(d.cleanUp, copyName) d.dumpStats(obj) }