Last active
August 29, 2015 14:21
-
-
Save slav123/33076e3986a110238337 to your computer and use it in GitHub Desktop.
Uploading to google storage using AWS S3 libraries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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