cos

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2017 License: MIT Imports: 22 Imported by: 0

README

go-cos

腾讯云对象存储服务 COS(Cloud Object Storage) Go SDK(API 版本:V5 版本的 XML API)。

Build Status Go Report Card GoDoc

install

go get -u bitbucket.org/mozillazg/go-cos

usage

所有的 API 在 examples 目录下都有对应的使用示例。

TODO

Service API:

  • Get Service

Bucket API:

  • Get Bucket
  • Get Bucket ACL
  • Get Bucket CORS
  • Get Bucket Location
  • Get Buket Lifecycle
  • Get Bucket Tagging
  • Put Bucket
  • Put Bucket ACL
  • Put Bucket CORS
  • Put Bucket Lifecycle
  • Put Bucket Tagging
  • Delete Bucket
  • Delete Bucket CORS
  • Delete Bucket Lifecycle
  • Delete Bucket Tagging
  • Head Bucket
  • List Multipart Uploads

Object API:

  • Append Object
  • Get Object
  • Get Object ACL
  • Put Object
  • Put Object ACL
  • Delete Object
  • Delete Multiple Object
  • Head Object
  • Options Object
  • Initiate Multipart Upload
  • Upload Part
  • List Parts
  • Complete Multipart Upload
  • Abort Multipart Upload

Documentation

Overview

Package cos 腾讯云对象存储服务 COS(Cloud Object Storage) Go SDK。

COS API Version

封装了 V5 版本的 XML API 。

Usage

在项目的 examples 目录下有各个 API 的使用示例 。

Authentication

默认所有 API 都是匿名访问. 如果想添加认证信息的话,可以通过自定义一个 http.Client 来添加认证信息.

比如, 使用内置的 AuthorizationTransport 来为请求增加 Authorization Header 签名信息:

client := cos.NewClient(b, &http.Client{
		Transport: &cos.AuthorizationTransport{
			SecretID:  "COS_SECRETID",
			SecretKey: "COS_SECRETKEY",
		},
	})

Index

Constants

View Source
const (
	// Version ...
	Version = "0.4.0"
)

Variables

This section is empty.

Functions

func AddAuthorizationHeader added in v0.4.0

func AddAuthorizationHeader(secretID, secretKey string, req *http.Request, authTime *AuthTime)

AddAuthorizationHeader 给 req 增加签名信息

func NewBucketURL added in v0.3.0

func NewBucketURL(bucketName, appID, region string, secure bool) *url.URL

NewBucketURL 生成 BaseURL 所需的 BucketURL

bucketName: bucket 名称
AppID: 应用 ID
Region: 区域代码: cn-east, cn-south, cn-north
secure: 是否使用 https

Types

type ACLGrant added in v0.4.0

type ACLGrant struct {
	Grantee    *ACLGrantee
	Permission string
}

ACLGrant ...

type ACLGrantee added in v0.4.0

type ACLGrantee struct {
	Type       string `xml:"type,attr"`
	UIN        string `xml:"uin"`
	SubAccount string `xml:"Subaccount,omitempty"`
}

ACLGrantee ...

type ACLHeaderOptions added in v0.3.0

type ACLHeaderOptions struct {
	XCosACL              string `header:"x-cos-acl,omitempty" url:"-" xml:"-"`
	XCosGrantRead        string `header:"x-cos-grant-read,omitempty" url:"-" xml:"-"`
	XCosGrantWrite       string `header:"x-cos-grant-write,omitempty" url:"-" xml:"-"`
	XCosGrantFullControl string `header:"x-cos-grant-full-control,omitempty" url:"-" xml:"-"`
}

ACLHeaderOptions ...

type ACLXml added in v0.4.0

type ACLXml struct {
	XMLName           xml.Name `xml:"AccessControlPolicy"`
	Owner             *Owner
	AccessControlList []ACLGrant `xml:"AccessControlList>Grant,omitempty"`
}

ACLXml ...

type AuthTime added in v0.2.0

type AuthTime struct {
	SignStartTime time.Time
	SignEndTime   time.Time
	KeyStartTime  time.Time
	KeyEndTime    time.Time
}

AuthTime 用于生成签名所需的 q-sign-time 和 q-key-time 相关参数

func NewAuthTime added in v0.2.0

func NewAuthTime(expire time.Duration) *AuthTime

NewAuthTime 生成 AuthTime 的便捷函数

expire: 从现在开始多久过期.

type AuthorizationTransport added in v0.4.0

type AuthorizationTransport struct {
	SecretID  string
	SecretKey string
	// 签名多久过期
	Expire time.Duration

	Transport http.RoundTripper
}

AuthorizationTransport 给请求增加 Authorization header

func (*AuthorizationTransport) RoundTrip added in v0.4.0

func (t *AuthorizationTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type BaseURL added in v0.3.0

type BaseURL struct {
	// 访问 bucket, object 相关 API 的基础 URL(不包含 path 部分): http://example.com
	BucketURL *url.URL
	// 访问 service API 的基础 URL(不包含 path 部分): http://example.com
	ServiceURL *url.URL
}

BaseURL 访问各 API 所需的基础 URL

type Bucket

type Bucket struct {
	Name       string
	AppID      string `xml:",omitempty"`
	Region     string `xml:"Location,omitempty"`
	CreateDate string `xml:",omitempty"`
}

Bucket ...

type BucketCORSRule

type BucketCORSRule struct {
	ID             string   `xml:"ID,omitempty"`
	AllowedMethods []string `xml:"AllowedMethod"`
	AllowedOrigins []string `xml:"AllowedOrigin"`
	AllowedHeaders []string `xml:"AllowedHeader,omitempty"`
	MaxAgeSeconds  int      `xml:"MaxAgeSeconds,omitempty"`
	ExposeHeaders  []string `xml:"ExposeHeader,omitempty"`
}

BucketCORSRule ...

type BucketGetACLResult added in v0.3.0

type BucketGetACLResult ACLXml

BucketGetACLResult ...

type BucketGetCORSResult added in v0.3.0

type BucketGetCORSResult struct {
	XMLName xml.Name         `xml:"CORSConfiguration"`
	Rules   []BucketCORSRule `xml:"CORSRule,omitempty"`
}

BucketGetCORSResult ...

type BucketGetLifecycleResult added in v0.3.0

type BucketGetLifecycleResult struct {
	XMLName xml.Name              `xml:"LifecycleConfiguration"`
	Rules   []BucketLifecycleRule `xml:"Rule,omitempty"`
}

BucketGetLifecycleResult ...

type BucketGetLocationResult added in v0.3.0

type BucketGetLocationResult struct {
	XMLName  xml.Name `xml:"LocationConstraint"`
	Location string   `xml:",chardata"`
}

BucketGetLocationResult ...

type BucketGetOptions

type BucketGetOptions struct {
	Prefix       string `url:"prefix,omitempty"`
	Delimiter    string `url:"delimiter,omitempty"`
	EncodingType string `url:"encoding-type,omitempty"`
	Marker       string `url:"marker,omitempty"`
	MaxKeys      int    `url:"max-keys,omitempty"`
}

BucketGetOptions ...

type BucketGetResult added in v0.3.0

type BucketGetResult struct {
	XMLName        xml.Name `xml:"ListBucketResult"`
	Name           string
	Prefix         string `xml:"Prefix,omitempty"`
	Marker         string `xml:"Marker,omitempty"`
	NextMarker     string `xml:"NextMarker,omitempty"`
	Delimiter      string `xml:"Delimiter,omitempty"`
	MaxKeys        int
	IsTruncated    bool
	Contents       []Object `xml:"Contents,omitempty"`
	CommonPrefixes []string `xml:"CommonPrefixes>Prefix,omitempty"`
	EncodingType   string   `xml:"Encoding-Type,omitempty"`
}

BucketGetResult ...

type BucketGetTaggingResult added in v0.3.0

type BucketGetTaggingResult struct {
	XMLName xml.Name           `xml:"Tagging"`
	TagSet  []BucketTaggingTag `xml:"TagSet>Tag,omitempty"`
}

BucketGetTaggingResult ...

type BucketLifecycleAbortIncompleteMultipartUpload

type BucketLifecycleAbortIncompleteMultipartUpload struct {
	DaysAfterInitiation string `xml:"DaysAfterInititation,omitempty"`
}

BucketLifecycleAbortIncompleteMultipartUpload ...

type BucketLifecycleExpiration

type BucketLifecycleExpiration struct {
	Date string `xml:"Date,omitempty"`
	Days int    `xml:"Days,omitempty"`
}

BucketLifecycleExpiration ...

type BucketLifecycleRule

type BucketLifecycleRule struct {
	ID                             string `xml:"ID,omitempty"`
	Prefix                         string
	Status                         string
	Transition                     *BucketLifecycleTransition                     `xml:"Transition,omitempty"`
	Expiration                     *BucketLifecycleExpiration                     `xml:"Expiration,omitempty"`
	AbortIncompleteMultipartUpload *BucketLifecycleAbortIncompleteMultipartUpload `xml:"AbortIncompleteMultipartUpload,omitempty"`
}

BucketLifecycleRule ...

type BucketLifecycleTransition

type BucketLifecycleTransition struct {
	Date         string `xml:"Date,omitempty"`
	Days         int    `xml:"Days,omitempty"`
	StorageClass string
}

BucketLifecycleTransition ...

type BucketPutACLOptions

type BucketPutACLOptions struct {
	Header *ACLHeaderOptions `url:"-" xml:"-"`
	Body   *ACLXml           `url:"-" header:"-"`
}

BucketPutACLOptions ...

type BucketPutCORSOptions added in v0.3.0

type BucketPutCORSOptions struct {
	XMLName xml.Name         `xml:"CORSConfiguration"`
	Rules   []BucketCORSRule `xml:"CORSRule,omitempty"`
}

BucketPutCORSOptions ...

type BucketPutLifecycleOptions added in v0.3.0

type BucketPutLifecycleOptions struct {
	XMLName xml.Name              `xml:"LifecycleConfiguration"`
	Rules   []BucketLifecycleRule `xml:"Rule,omitempty"`
}

BucketPutLifecycleOptions ...

type BucketPutOptions

type BucketPutOptions ACLHeaderOptions

BucketPutOptions ...

type BucketPutTaggingOptions added in v0.3.0

type BucketPutTaggingOptions struct {
	XMLName xml.Name           `xml:"Tagging"`
	TagSet  []BucketTaggingTag `xml:"TagSet>Tag,omitempty"`
}

BucketPutTaggingOptions ...

type BucketService

type BucketService service

BucketService ...

Bucket 相关 API

func (*BucketService) Delete

func (s *BucketService) Delete(ctx context.Context) (*Response, error)

Delete Bucket请求可以在指定账号下删除Bucket,删除之前要求Bucket为空。

https://www.qcloud.com/document/product/436/7732

func (*BucketService) DeleteCORS

func (s *BucketService) DeleteCORS(ctx context.Context) (*Response, error)

DeleteCORS ...

Delete Bucket CORS实现跨域访问配置删除。

https://www.qcloud.com/document/product/436/8283

func (*BucketService) DeleteLifecycle

func (s *BucketService) DeleteLifecycle(ctx context.Context) (*Response, error)

DeleteLifecycle ...

Delete Bucket Lifecycle请求实现删除生命周期管理。

(目前只支持华南园区)

https://www.qcloud.com/document/product/436/8284

func (*BucketService) DeleteTagging

func (s *BucketService) DeleteTagging(ctx context.Context) (*Response, error)

DeleteTagging ...

Delete Bucket Tagging接口实现删除指定Bucket的标签。

https://www.qcloud.com/document/product/436/8286

func (*BucketService) Get

Get Bucket请求等同于 List Object请求,可以列出该Bucket下部分或者所有Object,发起该请求需要拥有Read权限。

https://www.qcloud.com/document/product/436/7734

func (*BucketService) GetACL

GetACL 使用API读取Bucket的ACL表,只有所有者有权操作。

https://www.qcloud.com/document/product/436/7733

func (*BucketService) GetCORS

GetCORS ...

Get Bucket CORS实现跨域访问配置读取。

https://www.qcloud.com/document/product/436/8274

func (*BucketService) GetLifecycle

GetLifecycle ...

Get Bucket Lifecycle请求实现读取生命周期管理的配置。当配置不存在时,返回404 Not Found。

(目前只支持华南园区)

https://www.qcloud.com/document/product/436/8278

func (*BucketService) GetLocation

GetLocation ...

Get Bucket Location接口获取Bucket所在地域信息,只有Bucket所有者有权限读取信息。

https://www.qcloud.com/document/product/436/8275

func (*BucketService) GetTagging

GetTagging ...

Get Bucket Tagging接口实现获取指定Bucket的标签。

https://www.qcloud.com/document/product/436/8277

func (*BucketService) Head

func (s *BucketService) Head(ctx context.Context) (*Response, error)

Head Bucket请求可以确认是否存在该Bucket,是否有权限访问,Head的权限与Read一致。

当其存在时,返回 HTTP 状态码200;
当无权限时,返回 HTTP 状态码403;
当不存在时,返回 HTTP 状态码404。

https://www.qcloud.com/document/product/436/7735

func (*BucketService) ListMultipartUploads

ListMultipartUploads ...

List Multipart Uploads用来查询正在进行中的分块上传。单次最多列出1000个正在进行中的分块上传。

https://www.qcloud.com/document/product/436/7736

func (*BucketService) Put

Put Bucket请求可以在指定账号下创建一个Bucket。

https://www.qcloud.com/document/product/436/7738

func (*BucketService) PutACL

PutACL 使用API写入Bucket的ACL表,您可以通过Header:"x-cos-acl","x-cos-grant-read", "x-cos-grant-write","x-cos-grant-full-control"传入ACL信息,也可以通过body以XML格式传入ACL信息,

但是只能选择Header和Body其中一种,否则返回冲突。

Put Bucket ACL是一个覆盖操作,传入新的ACL将覆盖原有ACL。只有所有者有权操作。

"x-cos-acl":枚举值为public-read,private;public-read意味这个Bucket有公有读私有写的权限,
private意味这个Bucket有私有读写的权限。

"x-cos-grant-read":意味被赋予权限的用户拥有该Bucket的读权限
"x-cos-grant-write":意味被赋予权限的用户拥有该Bucket的写权限
"x-cos-grant-full-control":意味被赋予权限的用户拥有该Bucket的读写权限

https://www.qcloud.com/document/product/436/7737

func (*BucketService) PutCORS

func (s *BucketService) PutCORS(ctx context.Context, opt *BucketPutCORSOptions) (*Response, error)

PutCORS ...

Put Bucket CORS实现跨域访问设置,您可以通过传入XML格式的配置文件实现配置,文件大小限制为64 KB。

https://www.qcloud.com/document/product/436/8279

func (*BucketService) PutLifecycle

func (s *BucketService) PutLifecycle(ctx context.Context, opt *BucketPutLifecycleOptions) (*Response, error)

PutLifecycle ...

Put Bucket Lifecycle请求实现设置生命周期管理的功能。您可以通过该请求实现数据的生命周期管理配置和定期删除。

此请求为覆盖操作,上传新的配置文件将覆盖之前的配置文件。生命周期管理对文件和文件夹同时生效。

(目前只支持华南园区)

https://www.qcloud.com/document/product/436/8280

func (*BucketService) PutTagging

func (s *BucketService) PutTagging(ctx context.Context, opt *BucketPutTaggingOptions) (*Response, error)

PutTagging ...

Put Bucket Tagging接口实现给用指定Bucket打标签。用来组织和管理相关Bucket。

当该请求设置相同Key名称,不同Value时,会返回400。请求成功,则返回204。

https://www.qcloud.com/document/product/436/8281

type BucketTaggingTag

type BucketTaggingTag struct {
	Key   string
	Value string
}

BucketTaggingTag ...

type Client

type Client struct {
	UserAgent string
	BaseURL   *BaseURL

	Service *ServiceService
	Bucket  *BucketService
	Object  *ObjectService
	// contains filtered or unexported fields
}

A Client manages communication with the COS API.

func NewClient

func NewClient(uri *BaseURL, httpClient *http.Client) *Client

NewClient returns a new COS API client.

type CompleteMultipartUploadOptions added in v0.4.0

type CompleteMultipartUploadOptions struct {
	XMLName xml.Name `xml:"CompleteMultipartUpload"`
	Parts   []Object `xml:"Part"`
}

CompleteMultipartUploadOptions ...

type CompleteMultipartUploadResult added in v0.4.0

type CompleteMultipartUploadResult struct {
	XMLName  xml.Name `xml:"CompleteMultipartUploadResult"`
	Location string
	Bucket   string
	Key      string
	ETag     string
}

CompleteMultipartUploadResult ...

type DebugRequestTransport added in v0.3.0

type DebugRequestTransport struct {
	RequestHeader  bool
	RequestBody    bool // RequestHeader 为 true 时,这个选项才会生效
	ResponseHeader bool
	ResponseBody   bool // ResponseHeader 为 true 时,这个选项才会生效

	// debug 信息输出到 Writer 中, 默认是 os.Stderr
	Writer io.Writer

	Transport http.RoundTripper
}

DebugRequestTransport 会打印请求和响应信息, 方便调试.

func (*DebugRequestTransport) RoundTrip added in v0.3.0

func (t *DebugRequestTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type ErrorResponse

type ErrorResponse struct {
	XMLName   xml.Name       `xml:"Error"`
	Response  *http.Response `xml:"-"`
	Code      string
	Message   string
	Resource  string
	RequestID string `xml:"RequestId"`
	TraceID   string `xml:"TraceId,omitempty"`
}

ErrorResponse 包含 API 返回的错误信息

https://www.qcloud.com/document/product/436/7730

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Error ...

type InitiateMultipartUploadOptions added in v0.4.0

type InitiateMultipartUploadOptions struct {
	*ACLHeaderOptions
	*ObjectPutHeaderOptions
}

InitiateMultipartUploadOptions ...

type InitiateMultipartUploadResult added in v0.4.0

type InitiateMultipartUploadResult struct {
	XMLName  xml.Name `xml:"InitiateMultipartUploadResult"`
	Bucket   string
	Key      string
	UploadID string `xml:"UploadId"`
}

InitiateMultipartUploadResult ...

type Initiator

type Initiator Owner

Initiator ...

type ListMultipartUploadsOptions

type ListMultipartUploadsOptions struct {
	Delimiter      string `url:"delimiter,omitempty"`
	EncodingType   string `url:"encoding-type,omitempty"`
	Prefix         string `url:"prefix,omitempty"`
	MaxUploads     int    `url:"max-uploads,omitempty"`
	KeyMarker      string `url:"key-marker,omitempty"`
	UploadIDMarker string `url:"upload-id-marker,omitempty"`
}

ListMultipartUploadsOptions ...

type ListMultipartUploadsResult

type ListMultipartUploadsResult struct {
	XMLName            xml.Name `xml:"ListMultipartUploadsResult"`
	Bucket             string   `xml:"Bucket"`
	EncodingType       string   `xml:"Encoding-Type"`
	KeyMarker          string
	UploadIDMarker     string `xml:"UploadIdMarker"`
	NextKeyMarker      string
	NextUploadIDMarker string `xml:"NextUploadIdMarker"`
	MaxUploads         int
	IsTruncated        bool
	Uploads            []struct {
		Key          string
		UploadID     string `xml:"UploadId"`
		StorageClass string
		Initiator    *Initiator
		Owner        *Owner
		Initiated    string
	} `xml:"Upload,omitempty"`
	Prefix         string
	Delimiter      string   `xml:"delimiter,omitempty"`
	CommonPrefixes []string `xml:"CommonPrefixs>Prefix,omitempty"`
}

ListMultipartUploadsResult ...

type Object added in v0.4.0

type Object struct {
	Key          string `xml:",omitempty"`
	ETag         string `xml:",omitempty"`
	Size         int    `xml:",omitempty"`
	PartNumber   int    `xml:",omitempty"`
	LastModified string `xml:",omitempty"`
	StorageClass string `xml:",omitempty"`
	Owner        *Owner `xml:",omitempty"`
}

Object ...

type ObjectDeleteMultiOptions added in v0.3.0

type ObjectDeleteMultiOptions struct {
	XMLName xml.Name `xml:"Delete" header:"-"`
	Quiet   bool     `xml:"Quiet" header:"-"`
	Objects []Object `xml:"Object" header:"-"`
}

ObjectDeleteMultiOptions ...

type ObjectDeleteMultiResult added in v0.3.0

type ObjectDeleteMultiResult struct {
	XMLName        xml.Name `xml:"DeleteResult"`
	DeletedObjects []Object `xml:"Deleted,omitempty"`
	Errors         []struct {
		Key     string
		Code    string
		Message string
	} `xml:"Error,omitempty"`
}

ObjectDeleteMultiResult ...

type ObjectGetACLResult added in v0.3.0

type ObjectGetACLResult ACLXml

ObjectGetACLResult ...

type ObjectGetOptions added in v0.3.0

type ObjectGetOptions struct {
	ResponseContentType        string `url:"response-content-type,omitempty" header:"-"`
	ResponseContentLanguage    string `url:"response-content-language,omitempty" header:"-"`
	ResponseExpires            string `url:"response-expires,omitempty" header:"-"`
	ResponseCacheControl       string `url:"response-cache-control,omitempty" header:"-"`
	ResponseContentDisposition string `url:"response-content-disposition,omitempty" header:"-"`
	ResponseContentEncoding    string `url:"response-content-encoding,omitempty" header:"-"`
	Range                      string `url:"-" header:"Range,omitempty"`
	IfModifiedSince            string `url:"-" header:"If-Modified-Since,omitempty"`
}

ObjectGetOptions ...

type ObjectHeadOptions added in v0.3.0

type ObjectHeadOptions struct {
	IfModifiedSince string `url:"-" header:"If-Modified-Since,omitempty"`
}

ObjectHeadOptions ...

type ObjectListPartsOptions added in v0.3.0

type ObjectListPartsOptions struct {
	EncodingType     string `url:"Encoding-type,omitempty"`
	MaxParts         int    `url:"max-parts,omitempty"`
	PartNumberMarker int    `url:"part-number-marker,omitempty"`
}

ObjectListPartsOptions ...

type ObjectListPartsResult added in v0.3.0

type ObjectListPartsResult struct {
	XMLName              xml.Name `xml:"ListPartsResult"`
	Bucket               string
	EncodingType         string `xml:"Encoding-type,omitempty"`
	Key                  string
	UploadID             string     `xml:"UploadId"`
	Initiator            *Initiator `xml:"Initiator,omitempty"`
	Owner                *Owner     `xml:"Owner,omitempty"`
	StorageClass         string
	PartNumberMarker     int
	NextPartNumberMarker int `xml:"NextPartNumberMarker,omitempty"`
	MaxParts             int
	IsTruncated          bool
	Parts                []Object `xml:"Part,omitempty"`
}

ObjectListPartsResult ...

type ObjectOptionsOptions added in v0.3.0

type ObjectOptionsOptions struct {
	Origin                      string `url:"-" header:"Origin"`
	AccessControlRequestMethod  string `url:"-" header:"Access-Control-Request-Method"`
	AccessControlRequestHeaders string `url:"-" header:"Access-Control-Request-Headers,omitempty"`
}

ObjectOptionsOptions ...

type ObjectPutACLOptions added in v0.3.0

type ObjectPutACLOptions struct {
	Header *ACLHeaderOptions `url:"-" xml:"-"`
	Body   *ACLXml           `url:"-" header:"-"`
}

ObjectPutACLOptions ...

type ObjectPutHeaderOptions added in v0.3.0

type ObjectPutHeaderOptions struct {
	CacheControl       string `header:"Cache-Control,omitempty" url:"-"`
	ContentDisposition string `header:"Content-Disposition,omitempty" url:"-"`
	ContentEncoding    string `header:"Content-Encoding,omitempty" url:"-"`
	ContentType        string `header:"Content-Type,omitempty" url:"-"`
	Expect             string `header:"Expect,omitempty" url:"-"`
	Expires            string `header:"Expires,omitempty" url:"-"`
	XCosContentSHA1    string `header:"x-cos-content-sha1,omitempty" url:"-"`
	// 自定义的 x-cos-meta-* header
	XCosMetaXXX      *http.Header `header:"x-cos-meta-*,omitempty" url:"-"`
	XCosStorageClass string       `header:"x-cos-storage-class,omitempty" url:"-"`
}

ObjectPutHeaderOptions ...

type ObjectPutOptions added in v0.3.0

type ObjectPutOptions struct {
	*ACLHeaderOptions       `header:",omitempty" url:"-" xml:"-"`
	*ObjectPutHeaderOptions `header:",omitempty" url:"-" xml:"-"`
}

ObjectPutOptions ...

type ObjectService added in v0.2.0

type ObjectService service

ObjectService ...

Object 相关 API

func (*ObjectService) AbortMultipartUpload added in v0.3.0

func (s *ObjectService) AbortMultipartUpload(ctx context.Context, name, uploadID string) (*Response, error)

AbortMultipartUpload ...

Abort Multipart Upload用来实现舍弃一个分块上传并删除已上传的块。当您调用Abort Multipart Upload时, 如果有正在使用这个Upload Parts上传块的请求,则Upload Parts会返回失败。当该UploadID不存在时,会返回404 NoSuchUpload。

建议您及时完成分块上传或者舍弃分块上传,因为已上传但是未终止的块会占用存储空间进而产生存储费用。

https://www.qcloud.com/document/product/436/7740

func (*ObjectService) Append added in v0.3.0

func (s *ObjectService) Append(ctx context.Context, name string, position int, r io.Reader, opt *ObjectPutOptions) (*Response, error)

Append ...

Append请求可以将一个文件(Object)以分块追加的方式上传至 Bucket 中。使用Append Upload的文件必须事前被设定为Appendable。 当Appendable的文件被执行Put Object的操作以后,文件被覆盖,属性改变为Normal。

文件属性可以在Head Object操作中被查询到,当您发起Head Object请求时,会返回自定义Header『x-cos-object-type』,该Header只有两个枚举值:Normal或者Appendable。

追加上传建议文件大小1M - 5G。如果position的值和当前Object的长度不致,COS会返回409错误。 如果Append一个Normal的Object,COS会返回409 ObjectNotAppendable。

Appendable的文件不可以被复制,不参与版本管理,不参与生命周期管理,不可跨区域复制。

https://www.qcloud.com/document/product/436/7741

func (*ObjectService) CompleteMultipartUpload added in v0.3.0

func (s *ObjectService) CompleteMultipartUpload(ctx context.Context, name, uploadID string, opt *CompleteMultipartUploadOptions) (*CompleteMultipartUploadResult, *Response, error)

CompleteMultipartUpload ...

Complete Multipart Upload用来实现完成整个分块上传。当您已经使用Upload Parts上传所有块以后,你可以用该API完成上传。 在使用该API时,您必须在Body中给出每一个块的PartNumber和ETag,用来校验块的准确性。

由于分块上传的合并需要数分钟时间,因而当合并分块开始的时候,COS就立即返回200的状态码,在合并的过程中, COS会周期性的返回空格信息来保持连接活跃,直到合并完成,COS会在Body中返回合并后块的内容。

当上传块小于1 MB的时候,在调用该请求时,会返回400 EntityTooSmall; 当上传块编号不连续的时候,在调用该请求时,会返回400 InvalidPart; 当请求Body中的块信息没有按序号从小到大排列的时候,在调用该请求时,会返回400 InvalidPartOrder; 当UploadId不存在的时候,在调用该请求时,会返回404 NoSuchUpload。

建议您及时完成分块上传或者舍弃分块上传,因为已上传但是未终止的块会占用存储空间进而产生存储费用。

https://www.qcloud.com/document/product/436/7742

func (*ObjectService) Delete added in v0.3.0

func (s *ObjectService) Delete(ctx context.Context, name string) (*Response, error)

Delete Object请求可以将一个文件(Object)删除。

https://www.qcloud.com/document/product/436/7743

func (*ObjectService) DeleteMulti added in v0.3.0

DeleteMulti ...

Delete Multiple Object请求实现批量删除文件,最大支持单次删除1000个文件。 对于返回结果,COS提供Verbose和Quiet两种结果模式。Verbose模式将返回每个Object的删除结果; Quiet模式只返回报错的Object信息。

此请求必须携带x-cos-sha1用来校验Body的完整性。

https://www.qcloud.com/document/product/436/8289

func (*ObjectService) Get added in v0.3.0

func (s *ObjectService) Get(ctx context.Context, name string, opt *ObjectGetOptions) (*Response, error)

Get Object 请求可以将一个文件(Object)下载至本地。 该操作需要对目标 Object 具有读权限或目标 Object 对所有人都开放了读权限(公有读)。

https://www.qcloud.com/document/product/436/7753

func (*ObjectService) GetACL added in v0.3.0

GetACL Get Object ACL接口实现使用API读取Object的ACL表,只有所有者有权操作。

https://www.qcloud.com/document/product/436/7744

func (*ObjectService) Head added in v0.3.0

func (s *ObjectService) Head(ctx context.Context, name string, opt *ObjectHeadOptions) (*Response, error)

Head Object请求可以取回对应Object的元数据,Head的权限与Get的权限一致

https://www.qcloud.com/document/product/436/7745

func (*ObjectService) InitiateMultipartUpload added in v0.3.0

InitiateMultipartUpload ...

Initiate Multipart Upload请求实现初始化分片上传,成功执行此请求以后会返回Upload ID用于后续的Upload Part请求。

https://www.qcloud.com/document/product/436/7746

func (*ObjectService) ListParts added in v0.3.0

func (s *ObjectService) ListParts(ctx context.Context, name, uploadID string) (*ObjectListPartsResult, *Response, error)

ListParts ...

List Parts用来查询特定分块上传中的已上传的块。

https://www.qcloud.com/document/product/436/7747

func (*ObjectService) Options added in v0.3.0

func (s *ObjectService) Options(ctx context.Context, name string, opt *ObjectOptionsOptions) (*Response, error)

Options Object请求实现跨域访问的预请求。即发出一个 OPTIONS 请求给服务器以确认是否可以进行跨域操作。

当CORS配置不存在时,请求返回403 Forbidden。

https://www.qcloud.com/document/product/436/8288

func (*ObjectService) Put added in v0.3.0

func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, opt *ObjectPutOptions) (*Response, error)

Put Object请求可以将一个文件(Oject)上传至指定Bucket。

https://www.qcloud.com/document/product/436/7749

func (*ObjectService) PutACL added in v0.3.0

func (s *ObjectService) PutACL(ctx context.Context, name string, opt *ObjectPutACLOptions) (*Response, error)

PutACL 使用API写入Object的ACL表,您可以通过Header:"x-cos-acl", "x-cos-grant-read" , "x-cos-grant-write" ,"x-cos-grant-full-control"传入ACL信息, 也可以通过body以XML格式传入ACL信息,但是只能选择Header和Body其中一种,否则,返回冲突。

Put Object ACL是一个覆盖操作,传入新的ACL将覆盖原有ACL。只有所有者有权操作。

"x-cos-acl":枚举值为public-read,private;public-read意味这个Object有公有读私有写的权限, private意味这个Object有私有读写的权限。

"x-cos-grant-read":意味被赋予权限的用户拥有该Object的读权限

"x-cos-grant-write":意味被赋予权限的用户拥有该Object的写权限

"x-cos-grant-full-control":意味被赋予权限的用户拥有该Object的读写权限

https://www.qcloud.com/document/product/436/7748

func (*ObjectService) UploadPart added in v0.3.0

func (s *ObjectService) UploadPart(ctx context.Context, name, uploadID string, partNumber int, r io.Reader, opt *ObjectUploadPartOptions) (*Response, error)

UploadPart ...

Upload Part请求实现在初始化以后的分块上传,支持的块的数量为1到10000,块的大小为1 MB 到5 GB。 在每次请求Upload Part时候,需要携带partNumber和uploadID,partNumber为块的编号,支持乱序上传。

当传入uploadID和partNumber都相同的时候,后传入的块将覆盖之前传入的块。当uploadID不存在时会返回404错误,NoSuchUpload.

https://www.qcloud.com/document/product/436/7750

type ObjectUploadPartOptions added in v0.3.0

type ObjectUploadPartOptions struct {
	Expect          string `header:"Expect,omitempty" url:"-"`
	XCosContentSHA1 string `header:"x-cos-content-sha1" url:"-"`
}

ObjectUploadPartOptions ...

type Owner

type Owner struct {
	UIN         string `xml:"uin,omitmepty"`
	ID          string `xml:",omitmepty"`
	DisplayName string `xml:",omitmepty"`
}

Owner ...

type Response added in v0.3.0

type Response struct {
	*http.Response
}

Response API 响应

type ServiceGetResult added in v0.3.0

type ServiceGetResult struct {
	XMLName xml.Name `xml:"ListAllMyBucketsResult"`
	Owner   *Owner   `xml:"Owner"`
	Buckets []Bucket `xml:"Buckets>Bucket,omitempty"`
}

ServiceGetResult ...

type ServiceService

type ServiceService service

ServiceService ...

Service 相关 API

func (*ServiceService) Get

Get Service 接口实现获取该用户下所有Bucket列表。

该API接口需要使用Authorization签名认证, 且只能获取签名中AccessID所属账户的Bucket列表。

https://www.qcloud.com/document/product/436/8291

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL