English | 简体中文
- It's necessary for you to make sure your system have installed a Go environment which is new than 1.12.0.
If you use go mod
to manage your dependence, you can use the following command:
$ go get github.com/alibabacloud-go/tea-oss-sdk
package main
import (
"fmt"
ossClient "github.com/alibabacloud-go/tea-oss-sdk/client"
)
func main(){
config := new(ossClient.Config).SetAccessKeyId("your_access_key_id").
SetAccessKeySecret("your_access_key_secret").
SetType("access_key")
runtimeObject := new(ossClient.RuntimeObject).SetAutoretry(false).
SetMd5Threshold(1000).
SetMaxIdleConns(3)
client, err := ossClient.NewClient(config)
if err != nil {
fmt.Println(err)
}
// Upload file
body := bytes.NewReader([]byte("demo")) // body is a stream object
putObecjtReq := &PutObjectRequest{}
header := &PutObjectRequestHeader{}
header.SetStorageClass("Standard")
putObecjtReq.SetBucketName("demo").
SetObjectName("demo.txt").
SetBody(body).
SetHeader(header)
putObjectResp, err := client.PutObject(putObecjtReq, runtimeObject)
if err != nil {
fmt.Println(err)
}
fmt.Println(putObjectResp)
// Download file
getObjectReq := &GetObjectRequest{}
getObjectReq.SetBucketName("demo").
SetObjectName("demo.txt")
getObjectResp, err := client.GetObject(getObjectReq, runtimeObject)
if err != nil {
fmt.Println(err)
}
fmt.Println(getObjectResp)
}
Opening an Issue, Issues not conforming to the guidelines may be closed immediately.
Detailed changes for each release are documented in the release notes.
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.