Skip to content

Latest commit

 

History

History
83 lines (62 loc) · 1.94 KB

README-CN.md

File metadata and controls

83 lines (62 loc) · 1.94 KB

English | 简体中文

Alibaba Cloud OSS SDK for Go

要求

  • 您需要确保本地安装的 go 环境版本大于 1.12.0.

安装

你可以使用 go mod 来管理你的依赖,

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

  // 上传文件
  body := bytes.NewReader([]byte("demo")) // body 为任意的流
  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)

  // 下载文件
  getObjectReq := &GetObjectRequest{}
  getObjectReq.SetBucketName("demo").
    SetObjectName("demo.txt")
  getObjectResp, err := client.GetObject(getObjectReq, runtimeObject)
  if err != nil {
    fmt.Println(err)
  }

  fmt.Println(getObjectResp)
}    

问题

提交 Issue,不符合指南的问题可能会立即关闭。

发行说明

每个版本的详细更改记录在发行说明中。

相关

许可证

Apache-2.0

Copyright (c) 2009-present, Alibaba Cloud All rights reserved.