client

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type R2Client

type R2Client struct {
	// contains filtered or unexported fields
}

R2Client 处理 Cloudflare R2 的文件上传

func NewR2Client

func NewR2Client(cfg *R2Config) (*R2Client, error)

NewR2Client 使用提供的配置创建一个新的 R2Client

func (*R2Client) DeleteObject

func (r *R2Client) DeleteObject(ctx context.Context, objectKey string) error

DeleteObject 从 R2 删除对象

func (*R2Client) GeneratePresignedURL

func (r *R2Client) GeneratePresignedURL(ctx context.Context, objectKey string, expires time.Duration) (string, error)

GeneratePresignedURL 为对象生成预签名 URL

func (*R2Client) ListObjects

func (r *R2Client) ListObjects(ctx context.Context, prefix string, maxKeys int32) ([]string, error)

ListObjects 列出存储桶中具有给定前缀的对象

func (*R2Client) UploadAny

func (r *R2Client) UploadAny(ctx context.Context, source interface{}, objectKey string, contentType string) (*UploadResult, error)

UploadAny 是一个通用的上传方法,可以处理各种类型的输入 支持: 文件路径(string), []byte, io.Reader, *multipart.FileHeader

func (*R2Client) UploadBytes

func (r *R2Client) UploadBytes(ctx context.Context, data []byte, objectKey string, contentType string) (*UploadResult, error)

UploadBytes 上传字节数组到 R2

func (*R2Client) UploadData

func (r *R2Client) UploadData(ctx context.Context, reader io.Reader, objectKey string, contentType string, size int64) (*UploadResult, error)

UploadData 从 io.Reader 上传数据到 R2

func (*R2Client) UploadFile

func (r *R2Client) UploadFile(ctx context.Context, filePath string, objectKey string, contentType string) (*UploadResult, error)

UploadFile 从本地文件路径上传文件到 R2

func (*R2Client) UploadMultipartFile

func (r *R2Client) UploadMultipartFile(ctx context.Context, file *multipart.FileHeader, objectKey string, contentType string) (*UploadResult, error)

UploadMultipartFile 上传 multipart 文件到 R2

func (*R2Client) UploadReader

func (r *R2Client) UploadReader(ctx context.Context, reader io.Reader, objectKey string, contentType string, size int64) (*UploadResult, error)

UploadReader 从任何 io.Reader 上传数据到 R2 注意:如果提供的 reader 不是 io.ReadSeeker,此方法会将整个内容读入内存

type R2Config

type R2Config struct {
	AccountID       string // 账户ID
	AccessKeyID     string // 访问密钥ID
	AccessKeySecret string // 访问密钥密钥
	BucketName      string // 存储桶名称
	Region          string // 区域
	Endpoint        string // 端点
	CustomDomain    string // 自定义显示用的域名
}

R2Config 保存 Cloudflare R2 的配置信息

type UploadResult

type UploadResult struct {
	URL         string // 文件访问 URL
	Key         string // 文件键名
	Size        int64  // 文件大小(字节)
	ContentType string // 内容类型

}

UploadResult 包含已上传文件的信息

Jump to

Keyboard shortcuts

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