Skip to content

polym/go-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UPYUN Go SDK

Build Status

import "github.com/upyun/go-sdk/upyun"

UPYUN Go SDK, 集成:

Table of Contents

Examples

示例代码见 examples/

Projects using this SDK

Usage

UPYUN HTTP REST 接口

UpYun

type UpYun struct {
    Bucket    string    // 空间名(即服务名称)
    Username  string    // 操作员
    Passwd    string    // 密码
    ChunkSize int       // 块读取大小, 默认32KB
}

初始化 UpYun

func NewUpYun(bucket, username, passwd string) *UpYun

设置 API 访问域名

// Auto: Auto detected, based on user's internet
// Telecom: (ISP) China Telecom
// Cnc:     (ISP) China Unicom
// Ctt:     (ISP) China Tietong
const (
    Auto = iota
    Telecom
    Cnc
    Ctt
)

func (u *UpYun) SetEndpoint(ed int) error

获取空间存储使用量

func (u *UpYun) Usage() (int64, error)

创建目录

func (u *UpYun) Mkdir(key string) error

上传

func (u *UpYun) Put(key string, value io.Reader, useMD5 bool,
        headers map[string]string) (http.Header, error)

key 为 UPYUN 上的存储路径,value 既可以是文件,也可以是 bufferuseMD5 是否 MD5 校验,headers 自定义上传参数,除 上传参数,还可以设置 Content-Length,支持流式上传。流式上传需要指定 Contnet-Length,如需 MD5 校验,需要设置 Content-MD5

下载

func (u *UpYun) Get(key string, value io.Writer) (int, error)

此方法返回文件大小

删除

func (u *UpYun) Delete(key string) error

获取文件信息

type FileInfo struct {
    Size int64         // 文件大小
    Time time.Time     // 修改时间
    Name string        // 文件名
    Type string        // 类型,folder 或者 file
}

func (u *UpYun) GetInfo(key string) (*FileInfo, error)

获取文件列表

// 少量文件
func (u *UpYun) GetList(key string) ([]*FileInfo, error)

// 大量文件
func (u *UpYun) GetLargeList(key string, recursive bool) chan *FileInfo

key 必须为目录。对于目录下有大量文件的,建议使用 GetLargeList


UPYUN 缓存刷新接口

func (u *UpYun) Purge(urls []string) (string, error)

UPYUN HTTP 表单上传接口

UpYunForm

type UpYunForm struct {
    Secret    string    // 表单密钥
    Bucket    string    // 空间名(即服务名称)
}

初始化 UpYunForm

func NewUpYunForm(bucket, key string) *UpYunForm

FormAPIResp

type FormAPIResp struct {
    Code      int    `json:"code"`
    Msg       string `json:"message"`
    Url       string `json:"url"`
    Timestamp int64  `json:"time"`
    ImgWidth  int    `json:"image-width"`
    ImgHeight int    `json:"image-height"`
    ImgFrames int    `json:"image-frames"`
    ImgType   string `json:"image-type"`
    Sign      string `json:"sign"`
}

设置 API 访问域名

func (u *UpYunForm) SetEndpoint(ed int) error

上传文件

func (uf *UpYunForm) Put(fpath, saveas string, expireAfter int64,
    options map[string]string) (*FormAPIResp, error)

fpath 上传文件名,saveas UPYUN 存储保存路径,expireAfter 过期时间长度,options 上传参数。


UPYUN 分块上传接口

UpYunMultiPart

type UpYunMultiPart struct {
    Bucket    string        // 空间名(即服务名称)
    Secret    string        // 表单密钥
    BlockSize int64         // 分块大小,单位字节, 建议 1024000
}

UploadResp

type UploadResp struct {
    // returns after init request
    SaveToken string `json:"save_token"`
    // token_secert is equal to UPYUN Form API Secret
    Secret string `json:"token_secret"`
    // UPYUN Bucket Name
    Bucket string `json:"bucket_name"`
    // Number of Blocks
    Blocks   int   `json:"blocks"`
    Status   []int `json:"status"`
    ExpireAt int64 `json:"expire_at"`
}

MergeResp

type MergeResp struct {
    Path          string      `json:"path"`
    ContentType   string      `json:"mimetype"`
    ContentLength interface{} `json:"file_size"`
    LastModify    int64       `json:"last_modified"`
    Signature     string      `json:"signature"`
    ImageWidth    int         `json:"image_width"`
    ImageHeight   int         `json:"image_height"`
    ImageFrames   int         `json:"image_frames"`
}

初始化 UpYunMultiPart

func NewUpYunMultiPart(bucket, secret string, blocksize int64) *UpYunMultiPart

上传

func (ump *UpYunMultiPart) Put(fpath, saveas string,
    expireAfter int64, options map[string]interface{}) (*MergeResp, error)

UPYUN 音视频处理接口

UpYunMedia

type UpYunMedia struct {
    Username  string    // 操作员
    Passwd    string    // 密码
    Bucket    string    // 空间名(即服务名称)
}

MediaStatusResp

type MediaStatusResp struct {
    Tasks map[string]interface{} `json:"tasks"`
}

初始化 UpYunMedia

func NewUpYunMedia(bucket, user, pass string) *UpYunMedia

提交任务

func (upm *UpYunMedia) PostTasks(src, notify, accept string,
    tasks []map[string]interface{}) ([]string, error)

src 音视频文件 UPYUN 存储路径,notify 回调URL,accept 设置回调格式,可选 jsontasks 任务列表,返回结果为任务 id 列表。

查询进度

func (upm *UpYunMedia) GetProgress(task_ids string) (*MediaStatusResp, error)

task_ids 是多个 task_id, 连接起来。

About

UPYUN Go SDK

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%