文件上传
更新时间: 2019-03-14 10:05
文件上传使用本地文件作为对象的数据源,您可以通过ObsClient.PutFile上传本地文件。以下代码展示了如何进行文件上传:
- // 引入依赖包
- import (
- "fmt"
- "obs"
- )
- var ak = "*** Provide your Access Key ***"
- var sk = "*** Provide your Secret Key ***"
- var endpoint = "https://your-endpoint"
- // 创建ObsClient结构体
- var obsClient, _ = obs.New(ak, sk, endpoint)
- func main() {
- input := &obs.PutFileInput{}
- input.Bucket = "bucketname"
- input.Key = "objectkey"
- input.SourceFile = "localfile"
- output, err := obsClient.PutFile(input)
- if err == nil {
- fmt.Printf("RequestId:%s\n", output.RequestId)
- fmt.Printf("ETag:%s\n", output.ETag)
- } else if obsError, ok := err.(obs.ObsError); ok {
- fmt.Printf("Code:%s\n", obsError.Code)
- fmt.Printf("Message:%s\n", obsError.Message)
- }
- }
父主题:上传对象