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
2016-04-08 11:56:29 -07:00

32 lines
722 B
Go

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)
}