awss3

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StorageClass 存储类型
	StorageClass = "STANDARD_IA"

	// AccessKeyIDFieldName aws配置文件credentials的访问id字段名称
	AccessKeyIDFieldName = "aws_access_key_id"
	// SecretAccessKeyFieldName aws配置文件credentials的访问密钥字段名称
	SecretAccessKeyFieldName = "aws_secret_access_key"

	// UploadMethod 预签名上传
	UploadMethod = "put"
	// DownloadMethod 预签名下载
	DownloadMethod = "get"
)

Variables

This section is empty.

Functions

func InitS3

func InitS3(bucket string, basePath string, region string, credentialsFile string, credentialsValues ...string) error

InitS3 初始化s3

Types

type AwsS3

type AwsS3 struct {
	Bucket   string // aws的存储桶
	BasePath string // 结尾必须以路径分隔符号/结尾
	Region   string // 区域

	Session *session.Session // 会话
	S3      *s3.S3           // s3对象
	// contains filtered or unexported fields
}

AwsS3 封装aws s3对象

func GetS3

func GetS3() *AwsS3

GetS3 获取s3对象,如果未初始化就使用会发生panic

func NewAwsS3

func NewAwsS3(bucket string, basePath string, region string, credentialsFile string, credentialsValues ...string) (*AwsS3, error)

NewAwsS3 使用初始化s3,建议优先使用.aws/credentials文件,如果不配置文件,可以传递aws_access_key_id和aws_secret_access_key值

func (*AwsS3) CheckFileIsExist

func (a *AwsS3) CheckFileIsExist(awsFile string) error

CheckFileIsExist 检查对象是否存在

func (*AwsS3) DeleteFile

func (a *AwsS3) DeleteFile(awsFile string) error

DeleteFile 从s3删除文件

func (*AwsS3) DownloadToFile

func (a *AwsS3) DownloadToFile(awsFile string, localFile string) (int64, error)

DownloadToFile 从S3下载文件到本地

func (*AwsS3) GetPreSignedURL

func (a *AwsS3) GetPreSignedURL(method string, awsFile string, expirySeconds int) (string, error)

GetPreSignedURL 获取访问s3资源的签名url,给第三方上传和下载资源使用

func (*AwsS3) UploadFromFile

func (a *AwsS3) UploadFromFile(localFile string) (string, error)

UploadFromFile 把文件上传到s3,s3上的文件名和上传的文件名一致

func (*AwsS3) UploadFromReader

func (a *AwsS3) UploadFromReader(reader io.Reader, awsFile string) (string, error)

UploadFromReader 读取reader内容上传到s3,可以指定以文件名

func (*AwsS3) WithBucketAndBasePath

func (a *AwsS3) WithBucketAndBasePath(currentBasePath string, currentBucket ...string) *AwsS3

WithBucketAndBasePath 切换新的S3存储桶和基础路径,复制新的s3对象,但不会影响原s3,如果不填写bucket则使用默认值

Jump to

Keyboard shortcuts

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