获取对象属性
更新时间: 2019-03-14 10:05
您可以通过ObsClient.GetObjectMetadata来获取对象属性,包括对象长度,对象MIME类型,对象自定义元数据等信息。以下代码展示了如何获取对象属性:
- // 引入依赖包
- 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.GetObjectMetadataInput{}
- input.Bucket = "bucketname"
- input.Key = "objectkey"
- output, err := obsClient.GetObjectMetadata(input)
- if err == nil {
- fmt.Printf("StorageClass:%s\n", output.StorageClass)
- fmt.Printf("ETag:%s\n", output.ETag)
- fmt.Printf("ContentType:%s\n", output.ContentType)
- fmt.Printf("ContentLength:%d\n", output.ContentLength)
- fmt.Printf("Metadata:%v\n", output.Metadata)
- } else if obsError, ok := err.(obs.ObsError); ok {
- fmt.Printf("Code:%s\n", obsError.Code)
- fmt.Printf("Message:%s\n", obsError.Message)
- }
- }
父主题:管理对象