Last active
August 8, 2019 10:19
-
-
Save JesseYan/298d79e320d3e86c2a239b50b41b0639 to your computer and use it in GitHub Desktop.
aws s3 service, store object
This file contains 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
func spectreCase() error { | |
host := os.Getenv("SPECTRE_HOST") | |
key := os.Getenv("SPECTRE_KEY") | |
secret := os.Getenv("SPECTRE_SECRET") | |
if host == "" || key == "" || secret == "" { | |
fmt.Println("Error 环境变量SPECTRE_HOST、SPECTRE_KEY、SPECTRE_SECRET均不能为空") | |
} | |
var bucketName = "venus-table-bucket-test" | |
//var bucketName = "venus-table-bucket" //online | |
s := spectre.New(host, key, secret) | |
//err1 := s.spectreCase(bucketName) | |
//fmt.Println("spectreCase error:", err1) | |
a, err := s.ListBuckets() //2 buckets | |
fmt.Println("ListBuckets:", a) | |
var fileUUID = "112" | |
var path = "./112.xlsx" | |
//err = s.Upload(bucketName, fileUUID, path) | |
//fmt.Println("Upload path error:", err) | |
////os.Remove(path) | |
//file, err := ioutil.ReadFile(path) | |
//if err != nil { | |
// return err | |
//} | |
//err = s.Upload(bucketName, fileUUID, file) | |
//if err != nil { | |
// return err | |
//} | |
data, err := s.Download(bucketName, fileUUID) | |
if err != nil && err.Error() != "error ==> status code = 404, message = bucket not found" { | |
return err | |
} | |
//os.Remove(path) | |
err = ioutil.WriteFile(path, data, os.ModePerm) | |
if err != nil { | |
return err | |
} | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment