pcs

package module
v0.0.0-...-9c7a537 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2015 License: MIT Imports: 19 Imported by: 0

README

baidu-pcs

Golang SDK for Baidu PCS

Build Status

Documentation: GoDoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgument  = errors.New("baidu-pcs: invalid argument")
	ErrMinRapidFileSize = errors.New("baidu-pcs: rapid upload file size must > 256KB")
	ErrIncompleteFile   = errors.New("baidu-pcs: could not read the whole file")
)

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

func NewHttpClient

func NewHttpClient() *http.Client

Types

type AddTaskOptions

type AddTaskOptions struct {
	// 请求失效时间,如果有,则会校验
	Expires int `url:"expires,omitempty"`

	// 下载后的文件保存路径
	SavePath string `url:"save_path"`

	// 源文件的URL
	SourceURL string `url:"source_url"`

	// 下载限速,默认不限速
	RateLimit int `url:"rate_limit,omitempty"`

	// 下载超时时间,默认3600秒
	Timeout int `url:"timeout,omitempty"`

	// 下载完毕后的回调,默认为空
	Callback string `url:"callback,omitempty"`
}

type CancelTaskOptions

type CancelTaskOptions struct {
	// 请求失效时间,如果有,则会校验
	Expires int `url:"expires,omitempty"`

	// 要取消的任务ID号
	TaskId string `url:"task_id"`
}

type Client

type Client struct {
	BaseURL     *url.URL
	UploadURL   *url.URL
	DownloadURL *url.URL

	UserAgent   string
	AccessToken string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(accessToken string) *Client

func (*Client) AddOfflineDownloadTask

func (c *Client) AddOfflineDownloadTask(opt *AddTaskOptions) (int64, *http.Response, error)

添加离线下载任务

func (*Client) BatchCopy

func (c *Client) BatchCopy(pairs []*FTPair) (*MoveCopyResponse, *http.Response, error)

批量拷贝文件/目录

func (*Client) BatchDelete

func (c *Client) BatchDelete(paths []string) (*http.Response, error)

批量删除文件/目录

func (*Client) BatchGetMeta

func (c *Client) BatchGetMeta(paths []string) ([]*FileMeta, *http.Response, error)

批量获取文件/目录的元信息

func (*Client) BatchMove

func (c *Client) BatchMove(pairs []*FTPair) (*MoveCopyResponse, *http.Response, error)

批量移动文件/目录

func (*Client) BatchRestore

func (c *Client) BatchRestore(fsIds []string) (*RestoreResponse, *http.Response, error)

批量还原文件或目录

func (*Client) BlockUpload

func (c *Client) BlockUpload(srcPath string) (*File, *http.Response, error)

分片上传—文件分片及上传

func (*Client) CancelOfflineDownloadTask

func (c *Client) CancelOfflineDownloadTask(opt *CancelTaskOptions) (*http.Response, error)

取消离线下载任务

func (*Client) Copy

func (c *Client) Copy(from, to string) (*MoveCopyResponse, *http.Response, error)

拷贝单个文件/目录

func (*Client) CreateSuperFile

func (c *Client) CreateSuperFile(targetPath string, md5 []string, opt *FileOptions) (*File, *http.Response, error)

分片上传—合并分片文件 与分片文件上传的upload方法配合使用,可实现超大文件(>2G)上传,同时也可用于断点续传的场景。

func (*Client) Delete

func (c *Client) Delete(path string) (*http.Response, error)

删除单个文件/目录

func (*Client) Diff

func (c *Client) Diff(cursor string) (*http.Response, error)

增量更新查询 cursor: 用于标记更新断点。

  • 首次调用cursor=null;
  • 非首次调用,使用最后一次调用diff接口的返回结果中的cursor。

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

func (*Client) Download

func (c *Client) Download(path string) (*http.Response, error)

下载单个文件 path: 下载文件路径,以/开头的绝对路径。

func (*Client) DownloadStream

func (c *Client) DownloadStream(path string) (*http.Response, error)

下载流式文件

func (*Client) EmptyRecycle

func (c *Client) EmptyRecycle() (*http.Response, error)

清空回收站

func (*Client) Get

func (c *Client) Get(url string, v interface{}) (*http.Response, error)

func (*Client) GetMeta

func (c *Client) GetMeta(path string) (*FileMeta, *http.Response, error)

获取单个文件或目录的元信息。

func (*Client) GetQuota

func (c *Client) GetQuota() (*Quota, *http.Response, error)

获取当前用户空间配额信息

func (*Client) ListFiles

func (c *Client) ListFiles(opt *ListFilesOptions) ([]*File, *http.Response, error)

获取目录下的文件列表

func (*Client) ListOfflineDownloadTask

func (c *Client) ListOfflineDownloadTask(opt *ListTaskOptions) (*http.Response, error)

查询离线下载任务列表

func (*Client) ListRecycle

func (c *Client) ListRecycle(opt *ListRecycleOptions) (*ListRecycleResponse, *http.Response, error)

查询回收站文件,获取回收站中的文件及目录列表

func (*Client) ListStream

func (c *Client) ListStream(opt *ListStreamOptions) (*StreamFile, *http.Response, error)

获取流式文件列表

func (*Client) Mkdir

func (c *Client) Mkdir(path string) (*File, *http.Response, error)

创建目录

func (*Client) Move

func (c *Client) Move(from, to string) (*MoveCopyResponse, *http.Response, error)

移动单个文件/目录

func (*Client) NewDownloadRequest

func (c *Client) NewDownloadRequest(method, urlStr string, body io.Reader) (*http.Request, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) NewUploadRequest

func (c *Client) NewUploadRequest(method, urlStr string, body io.Reader) (*http.Request, error)

func (*Client) PartialDownload

func (c *Client) PartialDownload(path string, start, end int64) (*http.Response, error)

下载单个文件: 支持断点下载 start: byte end: byte

func (*Client) Post

func (c *Client) Post(url string, contentType string, body io.Reader, v interface{}) (*http.Response, error)

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values, v interface{}) (*http.Response, error)

func (*Client) QueryOfflineDownloadTask

func (c *Client) QueryOfflineDownloadTask(opt *QueryTaskOptions) (*http.Response, error)

精确查询离线下载任务

func (*Client) RapidUpload

func (c *Client) RapidUpload(opt *RapiduUploadOptions) (*File, *http.Response, error)

秒传一个文件。

func (*Client) Restore

func (c *Client) Restore(fsId string) (*RestoreResponse, *http.Response, error)

还原单个文件或目录 fsId: 所还原的文件或目录在PCS的临时唯一标识ID

func (*Client) Search

func (c *Client) Search(opt *SearchOptions) ([]*File, *http.Response, error)

按文件名搜索文件(不支持查找目录)。

func (*Client) Streaming

func (c *Client) Streaming(path, typ string) (*http.Response, error)

为当前用户进行视频转码并实现在线实时观看 path: 格式必须为m3u8,m3u,asf,avi,flv,gif,mkv,mov,mp4,m4a,3gp,3g2,mj2,mpeg,ts,rm,rmvb,webm typ: 目前支持以下格式:

M3U8_320_240、M3U8_480_224、M3U8_480_360、M3U8_640_480和M3U8_854_480

func (*Client) SumFile

func (c *Client) SumFile(path string) (contentLen int, contentMd5, sliceMd5 string, contentCrc32 uint32, err error)

计算文件的各种值

func (*Client) Thumbnail

func (c *Client) Thumbnail(opt *ThumbnailOptions) (*http.Response, error)

获取指定图片文件的缩略图

func (*Client) Upload

func (c *Client) Upload(srcPath string, opt *FileOptions) (*File, *http.Response, error)

上传单个文件 srcPath: 待上传文件的或者绝对路径/相对路径

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Message  string         `json:"error_msg"`  // error message
	Code     int            `json:"error_code"` // error code
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type FTPair

type FTPair struct {
	From string `json:"from"`
	To   string `json:"to"`
}

type File

type File struct {
	Path  string `json:"path"`  // 文件的绝对路径
	Size  uint64 `json:"size"`  // 文件大小(以字节为单位)
	Ctime uint64 `json:"ctime"` // 文件创建时间
	Mtime uint64 `json:"mtime"` // 文件修改时间
	Md5   string `json:"md5"`   // 文件的md5签名
	FsId  uint64 `json:"fs_id"` // 文件在PCS的临时唯一标识ID
	IsDir uint   `json:"isdir"` // 是否是目录的标识符: “0”为文件, “1”为目录
}

type FileMeta

type FileMeta struct {
	*File
	BlockList   string `json:"block_list"`
	IfHasSubDir uint   `json:"ifhassubdir"`
}

type FileOptions

type FileOptions struct {
	// 上传文件路径(含上传的文件名称)。
	Path string `url:"path"`

	// 可选值:
	// overwrite:表示覆盖同名文件;
	// newcopy:表示生成文件副本并进行重命名,命名规则为“文件名_日期.后缀”。
	OnDup string `url:"ondup,omitempty"`
}

type ListFilesOptions

type ListFilesOptions struct {
	// 需要list的目录,以/开头的绝对路径。
	Path string `url:"path"`

	// “asc”或“desc”,缺省采用降序排序。
	// asc(升序)
	// desc(降序)
	Order string `url:"order,omitempty"`

	// 排序字段,缺省根据文件类型排序:
	// time(修改时间)
	// name(文件名)
	// size(大小,注意目录无大小)
	By string `url:"by,omitempty"`

	// 返回条目控制,参数格式为:n1-n2。
	// 返回结果集的[n1, n2)之间的条目,缺省返回所有条目;n1从0开始。
	Limit string `url:"limit,omitempty"`
}

type ListRecycleOptions

type ListRecycleOptions struct {
	// 返回条目的起始值,缺省值为0
	Start int `url:"start,omitempty"`

	// 返回条目的长度,缺省值为1000
	Limit int `url:"limit,omitempty"`
}

type ListRecycleResponse

type ListRecycleResponse struct {
	List []*File `json:"list"`
}

type ListStreamOptions

type ListStreamOptions struct {
	// 类型分为video、audio、image及doc四种
	Type string `url:"type"`

	// 返回条目控制起始值,缺省值为0
	Start string `url:"start,omitempty"`

	// 返回条目控制长度,缺省为1000,可配置
	Limit string `url:"limit,omitempty"`

	// 需要过滤的前缀路径,如:/apps/album
	FilterPath string `url:"filter_path,omitempty"`
}

type ListTaskOptions

type ListTaskOptions struct {
	// 请求失效时间,如果有,则会校验
	Expires int `url:"expires,omitempty"`

	// 查询任务起始位置,默认为0
	Start int `url:"start,omitempty"`

	// 设定返回任务数量,默认为10
	Limit int `url:"limit,omitempty"`

	// 0:降序,默认值
	// 1:升序
	Asc int `url:"asc,omitempty"`

	// 源地址URL,默认为空
	SourceURL string `url:"source_url,omitempty"`

	// 文件保存路径,默认为空
	SavePath string `url:"save_path,omitempty"`

	// 任务创建时间,默认为空
	CreateTime int `url:"create_time,omitempty"`

	// 任务状态,默认为空
	Status int `url:"status,omitempty"`

	// 是否需要返回任务信息:
	// 0:不需要
	// 1:需要,默认为1
	NeedTaskInfo int `url:"need_task_info,omitempty"`
}

type MoveCopyResponse

type MoveCopyResponse struct {
	Extra struct {
		List []struct {
			To   string `json:"to"`
			From string `json:"from"`
		} `json:"list"`
	} `json:"extra"`
}

type QueryTaskOptions

type QueryTaskOptions struct {
	// 请求失效时间,如果有,则会校验
	Expires int `url:"expires,omitempty"`

	// 要查询的任务ID信息,如:1,2,3,4
	TaskIds string `url:"task_ids"`

	// 0:查任务信息
	// 1:查进度信息,默认为1
	OpType int `url:"op_type"`
}

type Quota

type Quota struct {
	Quota uint64 `json:"quota"`
	Used  uint64 `json:"used"`
}

type RapiduUploadOptions

type RapiduUploadOptions struct {
	// 上传文件的全路径名
	Path string `url:"path"`

	// 待秒传的文件长度
	ContentLength int `url:"content-length"`

	// 待秒传的文件的MD5
	ContentMd5 string `url:"content-md5"`

	// 待秒传文件校验段的MD5
	SliceMd5 string `url:"slice-md5"`

	// 待秒传文件CRC32
	ContentCrc32 string `url:"content-crc32"`

	// overwrite:表示覆盖同名文件;
	// newcopy:表示生成文件副本并进行重命名,命名规则为“文件名_日期.后缀”。
	Ondup string `url:"ondup,omitempty"`
}

type RestoreResponse

type RestoreResponse struct {
	Extra struct {
		List []struct {
			FsID string `json:"fs_id"`
		} `json:"list"`
	} `json:"extra"`
}

type SearchOptions

type SearchOptions struct {
	// 需要检索的目录
	Path string `url:"path"`

	// 关键词
	Word string `url:"wd"`

	// 是否递归
	// “0”表示不递归
	// “1”表示递归
	// 缺省为“0”
	Re string `url:"re,omitempty"`
}

type StreamFile

type StreamFile struct {
	Total uint    `json:"total"`
	Start uint    `json:"start"`
	Limit uint    `json:"limit"`
	List  []*File `json:"list"`
}

type ThumbnailOptions

type ThumbnailOptions struct {
	// 源图片的路径
	Path string `url:"path"`

	// 缩略图的质量,默认为“100”,取值范围(0,100]
	Quality int32 `url:"quality,omitempty"`

	// 指定缩略图的高度,取值范围为(0,1600]
	Height int `url:"height"`

	// 指定缩略图的宽度,取值范围为(0,1600]
	Width int `url:"width"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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