oss

package
v0.0.0-...-5ef37d6 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

权限控制 https://help.aliyun.com/zh/oss/developer-reference/access-control-1/

https://github.com/aliyun/oss-browser

https://help.aliyun.com/zh/oss/developer-reference/delete-objects-11

下载文件 https://help.aliyun.com/zh/oss/developer-reference/overview-27

列举文件 https://help.aliyun.com/zh/oss/developer-reference/list-objects-10

管理文件 https://help.aliyun.com/zh/oss/developer-reference/manage-objects-11

oss客户端,必须先调用 Init 初始化 https://help.aliyun.com/zh/oss/ https://help.aliyun.com/zh/oss/developer-reference/introduction-3

数据处理 https://help.aliyun.com/document_detail/410762.html

上传文件 https://help.aliyun.com/document_detail/32147.html

Index

Constants

View Source
const (
	ACLPrivate         = oss.ACLPrivate         // 私有读,私有写,bucket默认
	ACLPublicRead      = oss.ACLPublicRead      // 公开读,私有写
	ACLPublicReadWrite = oss.ACLPublicReadWrite // 公开读,公开写
	ACLDefault         = oss.ACLDefault         // 适用于object,继承bucket权限,object默认
)

Access Control List权限

Variables

View Source
var (
	// 指定最大对象数
	MaxKeys = oss.MaxKeys
	// 指定分隔符 oss.Delimiter("/")
	Delimiter = oss.Delimiter
)
View Source
var Client *client

Functions

func DeleteAll

func DeleteAll(prefix string, f func(oss.ObjectProperties) bool, test bool) error

DeleteAll 删除所有指定前缀对象,f返回true表示忽略 设置test表示只输出删除对象,不实际删除

func DeleteObject

func DeleteObject(key string) error

DeleteObject 删除单个对象,只能删除空文件夹 文件夹以/结尾

func DeleteObjects

func DeleteObjects(keys ...string) error

DeleteObjects 删除多个对象 文件夹以/结尾

func DelimiterSlash

func DelimiterSlash(prefix string) []oss.Option

DelimiterSlash 指定目录前缀和/分隔符 prefix传目录路径,如果没有后缀/,会自动添加

func First

func First(prefix string) (*oss.ObjectProperties, error)

First 获取指定前缀的第一个对象

func GetObject

func GetObject(objectKey string, options ...oss.Option) ([]byte, error)

GetObject 读取文件字节

func GetObjectStr

func GetObjectStr(objectKey string, options ...oss.Option) (string, error)

GetObjectStr 读取文件字符串

func GetObjectToFile

func GetObjectToFile(objectKey, p string, options ...oss.Option) (string, error)

GetObjectToFile 下载文件 p指定目录 返回目录+文件名 自动创建目录

func Init

func Init(
	endpoint, accessKeyID, accessKeySecret, bucketName string,
	options ...oss.ClientOption,
) error

Init 初始化oss客户端 endpoint 是oss数据中心地址 例如https://oss-cn-hangzhou.aliyuncs.com https://help.aliyun.com/zh/oss/user-guide/regions-and-endpoints

func InitEnv

func InitEnv() error

InitEnv 使用环境变量初始化oss客户端 https://help.aliyun.com/zh/oss/developer-reference/go-configure-access-credentials

func InitToken

func InitToken(token string) (string, error)

InitToken 初始化oss客户端,使用oss browser auth token 返回token可访问的路径前缀 path/ https://github.com/aliyun/oss-browser/blob/develop/docs/authToken.md https://help.aliyun.com/zh/oss/developer-reference/go-configure-access-credentials

func IsDir

func IsDir(o oss.ObjectProperties) bool

IsDir 判断oss对象是否为目录

func IsObjectExist

func IsObjectExist(key string) (bool, error)

IsObjectExist 检查对象是否存在

func ListObjects

func ListObjects(options ...oss.Option) (*oss.ListObjectsResultV2, error)

ListObjects 获取多个对象

func ListObjectsPrefix

func ListObjectsPrefix(prefix string) (*oss.ListObjectsResultV2, error)

ListObjectsPrefix 获取多个对象 指定前缀 自动去掉prefix开头的/

func ListObjectsSlash

func ListObjectsSlash(prefix string) (*oss.ListObjectsResultV2, error)

ListObjectsSlash 获取多个对象 指定目录前缀和/分隔符 prefix传目录路径,如果没有后缀/,会自动添加 自动去掉prefix开头的/

返回 oss.ListObjectsResultV2.Objects 指定目录下文件 有时会包含指定的目录前缀 oss.ListObjectsResultV2.CommonPrefixes 指定目录下子目录

func Modify

func Modify(f func([]byte) []byte, objectKey string, options ...oss.Option) error

Modify 修改文件,先读取文件字节,修改后上传 options 是读取文件的选项

func Prefix

func Prefix(prefix string) oss.Option

Prefix 指定路径前缀

func PutObject

func PutObject(objectKey string, reader io.Reader, options ...oss.Option) error

PutObject 放文件,如果文件存在会覆盖

func PutObjectBytes

func PutObjectBytes(objectKey string, bs []byte, options ...oss.Option) error

PutObjectBytes 将bytes作为文件放到oss

func PutObjectFromFile

func PutObjectFromFile(objectKey, filePath string, options ...oss.Option) error

PutObjectFromFile 上传本地文件到oss objectKey 不能以斜杆开头

func PutObjectFromFileACL

func PutObjectFromFileACL(objectKey, filePath string, acl oss.ACLType) error

PutObjectFromFileACL 上传本地文件到oss,并修改acl权限

func PutObjectString

func PutObjectString(objectKey string, s string, options ...oss.Option) error

PutObjectString 将字符串作为文件放到oss

func PutObjectURL

func PutObjectURL(objectKey string, u string, options ...oss.Option) error

PutObjectURL 将url中的文件放到oss

func SignURL

func SignURL(objectKey string, expiredInSec int64, options ...oss.Option) (string, error)

SignURL 生成私有文件访问地址 http://bucket.oss-cn-shenzhen.aliyuncs.com/tmp.txt?Expires=1695707083&OSSAccessKeyId=&Signature=

func VideoSnapshot

func VideoSnapshot(width, height int) string

VideoSnapshot 视频截帧参数值 https://help.aliyun.com/document_detail/64555.html 使用视频截帧时,按视频截帧截取的图片数量计费。 截图宽高都指定为0,使用视频宽高,一个指定为0,则自动计算 如果视频可以公开读,截图地址是在视频地址后加 ?x-oss-process=参数值

func VideoSnapshotSignURL

func VideoSnapshotSignURL(objectKey string, expiredInSec int64, width, height int) (string, error)

VideoSnapshotSignURL 生成私有文件视频截帧URL

Types

type AuthToken

type AuthToken struct {
	ID         string `json:"id"`         // access key id
	Secret     string `json:"secret"`     // access key secret
	SToken     string `json:"stoken"`     // security token
	Privilege  string `json:"privilege"`  // 权限
	Expiration string `json:"expiration"` // 过期时间
	OssPath    string `json:"osspath"`    // oss路径 oss://bucket/path/
	Region     string `json:"region"`     // 区域
	EpTpl      string `json:"eptpl"`      // endpoint
	// 从json字段里解析
	Bucket     string `json:"bucket"`     // 桶
	PathPrefix string `json:"pathPrefix"` // oss路径path部分 path/
	ExpireTs   int64  `json:"expireTs"`   // 过期时间戳
}

AuthToken 授权码结构 https://github.com/aliyun/oss-browser/blob/develop/docs/authToken.md

func ParseAuthToken

func ParseAuthToken(token string) (*AuthToken, error)

ParseAuthToken 解析授权码

type ListObjectsResultV2

type ListObjectsResultV2 = oss.ListObjectsResultV2

oss.Bucket.ListObjectsV2()结果 Objects 对象列表 指定prefix/前缀时,有时会包含prefix/对象 CommonPrefixes 被oss.Delimiter("/")分隔的目录路径

type ObjectProperties

type ObjectProperties = oss.ObjectProperties

oss对象 Key 对象名 目录以斜杆结尾 Size 对象字节数 LastModified last modified time

Jump to

Keyboard shortcuts

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