This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/vendor/google.golang.org/api/examples/storage.go

33 lines
722 B
Go
Raw Normal View History

2016-04-09 00:26:29 +05:30
package main
import (
"fmt"
"log"
"net/http"
"os"
storage "google.golang.org/api/storage/v1"
)
func init() {
registerDemo("storage", storage.DevstorageRead_writeScope, storageMain)
}
func storageMain(client *http.Client, argv []string) {
if len(argv) != 2 {
fmt.Fprintln(os.Stderr, "Usage: storage filename bucket (to upload an object)")
return
}
service, _ := storage.New(client)
filename := argv[0]
bucket := argv[1]
goFile, err := os.Open(filename)
if err != nil {
log.Fatalf("error opening %q: %v", filename, err)
}
storageObject, err := service.Objects.Insert(bucket, &storage.Object{Name: filename}).Media(goFile).Do()
log.Printf("Got storage.Object, err: %#v, %v", storageObject, err)
}