Skip to content

Instantly share code, notes, and snippets.

@slav123 slav123/gs.go
Last active Aug 29, 2015

Embed
What would you like to do?
Uploading to google storage using AWS S3 libraries
package main
import (
"github.com/goamz/goamz/aws"
"github.com/goamz/goamz/s3"
"log"
)
var (
AccessKeyId, SecretAccessKey, Bucket string
Expire int
)
func main() {
AccessKeyId = ""
SecretAccessKey = ""
Bucket = ""
auth := aws.Auth{AccessKey: AccessKeyId, SecretKey: SecretAccessKey}
client := s3.New(auth, aws.Region{Name: "gs", S3Endpoint: "https://storage.googleapis.com"})
object := "download.txt"
b := client.Bucket(Bucket)
data, err := b.Get(object)
if err != nil {
log.Println("failed to get object :" + object + ": from bucket " + Bucket)
log.Println(err)
} else {
log.Println("yey :" + object + ": from bucket " + Bucket + string(data))
}
//
param := map[string][]string{
"Content-Type": {"text/plain"},
"x-goog-acl": {"private"},
}
path := "upload.txt"
err = b.PutHeader(path, data, param, s3.Private)
if err != nil {
log.Println("failed to store object :" + path + ":" + " on :" + Bucket)
log.Println(err)
} else {
log.Println("succesfully stored :" + path + ":" + " on :" + Bucket)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.