uploadx

package
v0.3.40 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeLocal  = "local"
	TypeAliyun = "aliyun"
)

StorageType 存储类型常量

Variables

This section is empty.

Functions

This section is empty.

Types

type AliYunConf

type AliYunConf struct {
	Endpoint        string `json:"endpoint"`
	AccessKeyId     string `json:"access-key-id"`
	AccessKeySecret string `json:"access-key-secret"`
	BucketName      string `json:"bucket-name"`
	BucketUrl       string `json:"bucket-url"`
	BasePath        string `json:"base-path"`
}

type AliyunOSS added in v0.3.40

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

AliyunOSS 阿里云OSS存储

func NewAliyunOSS added in v0.3.40

func NewAliyunOSS(config *Config) (*AliyunOSS, error)

NewAliyunOSS 创建阿里云OSS存储 使用前需要安装: go get github.com/aliyun/aliyun-oss-go-sdk/oss

func (*AliyunOSS) Delete added in v0.3.40

func (s *AliyunOSS) Delete(path string) error

Delete 删除文件

func (*AliyunOSS) Exists added in v0.3.40

func (s *AliyunOSS) Exists(path string) (bool, error)

Exists 检查文件是否存在

func (*AliyunOSS) GetInfo added in v0.3.40

func (s *AliyunOSS) GetInfo(path string) (*FileInfo, error)

GetInfo 获取文件信息

func (*AliyunOSS) GetURL added in v0.3.40

func (s *AliyunOSS) GetURL(path string, expires time.Duration) (string, error)

GetURL 获取文件访问URL

func (*AliyunOSS) Upload added in v0.3.40

func (s *AliyunOSS) Upload(path string, file io.Reader, contentType string) (string, error)

Upload 上传文件

func (*AliyunOSS) UploadWithOptions added in v0.3.40

func (s *AliyunOSS) UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)

UploadWithOptions 带选项的上传

type AwsConf

type AwsConf struct {
	Bucket           string `json:"bucket"`
	Region           string `json:"region"`
	Endpoint         string `json:"endpoint"`
	SecretID         string `json:"secret-id"`
	SecretKey        string `json:"secret-key"`
	BaseURL          string `json:"base-url"`
	PathPrefix       string `json:"path-prefix"`
	S3ForcePathStyle bool   `json:"s3-force-path-style"`
	DisableSSL       bool   `json:"disable-ssl"`
}

type AwsOSS

type AwsOSS struct {
	Conf AwsConf
}

func NewAwsOSS

func NewAwsOSS(conf AwsConf) *AwsOSS

func (*AwsOSS) DeleteFile

func (*AwsOSS) DeleteFile(key string) error

func (*AwsOSS) UploadFile

func (*AwsOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)

type CloudflareR2Conf

type CloudflareR2Conf struct {
	Bucket          string `json:"bucket"`
	BaseURL         string `json:"base-url"`
	Path            string `json:"path"`
	AccountID       string `json:"account-id"`
	AccessKeyID     string `json:"access-key-id"`
	SecretAccessKey string `json:"secret-access-key"`
}

type Config added in v0.3.40

type Config struct {
	Type      string `mapstructure:"type"`      // 存储类型:local, aliyun
	Endpoint  string `mapstructure:"endpoint"`  // 端点地址
	Bucket    string `mapstructure:"bucket"`    // 存储桶名称
	AccessKey string `mapstructure:"accessKey"` // 访问密钥ID
	SecretKey string `mapstructure:"secretKey"` // 访问密钥Secret
	Region    string `mapstructure:"region"`    // 区域
	Domain    string `mapstructure:"domain"`    // 自定义域名(CDN)
	IsPrivate bool   `mapstructure:"isPrivate"` // 是否私有(影响URL生成)
	BasePath  string `mapstructure:"basePath"`  // 基础路径
}

Config 存储配置

type FileInfo added in v0.3.40

type FileInfo struct {
	Path         string    // 文件路径
	Size         int64     // 文件大小(字节)
	ContentType  string    // MIME类型
	LastModified time.Time // 最后修改时间
	ETag         string    // ETag
	URL          string    // 访问URL
}

FileInfo 文件信息

type HuaWeiConf

type HuaWeiConf struct {
	Path      string `json:"path" yaml:"path"`
	Bucket    string `json:"bucket" yaml:"bucket"`
	Endpoint  string `json:"endpoint" yaml:"endpoint"`
	AccessKey string `json:"access-key" yaml:"access-key"`
	SecretKey string `json:"secret-key" yaml:"secret-key"`
}

type HwOSS

type HwOSS struct {
	Conf HuaWeiConf
}

func NewHwOSS

func NewHwOSS(conf HuaWeiConf) *HwOSS

func (*HwOSS) DeleteFile

func (*HwOSS) DeleteFile(key string) error

func (*HwOSS) UploadFile

func (*HwOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)

type LocalConf

type LocalConf struct {
	Path      string `json:"path"`       // 本地文件访问路径
	StorePath string `json:"store-path"` // 本地文件存储路径
}

type LocalOSS

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

func NewLocalOSS

func NewLocalOSS(conf LocalConf) *LocalOSS

func (*LocalOSS) DeleteFile

func (m *LocalOSS) DeleteFile(key string) error

func (*LocalOSS) UploadFile

func (m *LocalOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)

type MinIoConf

type MinIoConf struct {
	MinIOAccessKeyID     string `json:"minIOAccessKeyID"`     //admin
	MinIOAccessSecretKey string `json:"minIOAccessSecretKey"` //MinIOAccessSecretKey
	MinIOEndpoint        string `json:"minIOEndpoint"`        //localhost:9000
	MinIOBucketLocation  string `json:"minIOBucketLocation"`  //cn-north-1
	MinIOSSLBool         bool   `json:"minIOSSLBool"`
	MinIOBucket          string `json:"minIOBucket"` //mymusic
	MinIOBasePath        string `json:"minIoBasePath"`
}

type MinioOSS

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

func NewMinioOSS

func NewMinioOSS(conf MinIoConf) *MinioOSS

func (*MinioOSS) DeleteFile

func (m *MinioOSS) DeleteFile(key string) error

func (*MinioOSS) UploadFile

func (m *MinioOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)

type OSS

type OSS interface {
	UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)
	DeleteFile(key string) error
}

func NewOss

func NewOss(conf OSSConf) OSS

type OSSConf

type OSSConf struct {
	Type        OssType     `json:"type"`
	LocalConf   LocalConf   `json:"localConf,omitempty,optional"`
	MinIoConf   MinIoConf   `json:"minioConf,omitempty,optional"`
	AliYunConf  AliYunConf  `json:"aliyunConf,omitempty,optional"`
	TencentConf TencentConf `json:"tencentConf,omitempty,optional"`
	QiNiuConf   QiNiuConf   `json:"qiNiuConf,omitempty,optional"`
	AwsConf     AwsConf     `json:"awsConf,omitempty,optional"`
	HuaWeiConf  HuaWeiConf  `json:"huaWeiConf,omitempty,optional"`
}

type OssType

type OssType int
const (
	LocalType OssType = iota
	MinioType
	AliYunType
	TencentType
	QiNiuType
	AwsType
	HuaWeiType
)

type QiNiuConf

type QiNiuConf struct {
	Zone          string `json:"zone"`            // 存储区域
	Bucket        string `json:"bucket"`          // 空间名称
	ImgPath       string `json:"img-path"`        // CDN加速域名
	AccessKey     string `json:"access-key"`      // 秘钥AK
	SecretKey     string `json:"secret-key"`      // 秘钥SK
	UseHTTPS      bool   `json:"use-https"`       // 是否使用https
	UseCdnDomains bool   `json:"use-cdn-domains"` // 上传是否使用CDN上传加速
}

type QiNiuOSS

type QiNiuOSS struct {
	Conf QiNiuConf
}

func NewQiNiuOSS

func NewQiNiuOSS(conf QiNiuConf) *QiNiuOSS

func (*QiNiuOSS) DeleteFile

func (*QiNiuOSS) DeleteFile(key string) error

func (*QiNiuOSS) UploadFile

func (*QiNiuOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)

type Storage added in v0.3.40

type Storage interface {
	// Upload 上传文件
	// path: 存储路径(如:uploads/2024/01/01/file.jpg)
	// file: 文件内容
	// contentType: 文件MIME类型
	Upload(path string, file io.Reader, contentType string) (string, error)

	// UploadWithOptions 带选项的上传
	UploadWithOptions(path string, file io.Reader, opts *UploadOptions) (string, error)

	// Delete 删除文件
	Delete(path string) error

	// GetURL 获取文件访问URL
	// path: 存储路径
	// expires: 过期时间(0表示永久,>0表示生成临时签名URL)
	GetURL(path string, expires time.Duration) (string, error)

	// Exists 检查文件是否存在
	Exists(path string) (bool, error)

	// GetInfo 获取文件信息
	GetInfo(path string) (*FileInfo, error)
}

Storage 对象存储接口(支持多种云服务商)

type TencentConf

type TencentConf struct {
	Bucket     string `json:"bucket"`
	Region     string `json:"region"`
	SecretID   string `json:"secret-id"`
	SecretKey  string `json:"secret-key"`
	BaseURL    string `json:"base-url"`
	PathPrefix string `json:"path-prefix"`
}

type TencentOSS

type TencentOSS struct {
	Conf TencentConf
}

func NewTencentOSS

func NewTencentOSS(conf TencentConf) *TencentOSS

func (*TencentOSS) DeleteFile

func (*TencentOSS) DeleteFile(key string) error

func (*TencentOSS) UploadFile

func (*TencentOSS) UploadFile(file multipart.File, fileHeader *multipart.FileHeader) (*UploadInfo, error)

type UploadInfo

type UploadInfo struct {
	Path string `json:"path"`
	Hash string `json:"hash,optional"`
	Ext  string `json:"ext,optional"`
	Size int64  `json:"size,optional"`
}

type UploadOptions added in v0.3.40

type UploadOptions struct {
	ContentType        string            // MIME类型
	CacheControl       string            // 缓存控制
	ContentDisposition string            // 内容处置
	Metadata           map[string]string // 自定义元数据
	ACL                string            // 访问控制(public-read, private等)
}

UploadOptions 上传选项

Jump to

Keyboard shortcuts

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