storage

package
v0.0.0-...-fb568f1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissedUploadID     = errors.New("upload id is missed or empty")
	ErrNoCompletedParts   = errors.New("no completed parts, nothing to upload")
	ErrTotalParts         = errors.New("total parts can be between 1 and 10000")
	ErrPartNum            = errors.New("part number can be between 1 and total parts")
	ErrFileEmpty          = errors.New("file is empty")
	ErrInvalidContentType = errors.New("invalid content type")
	ErrInvalidReader      = errors.New("invalid reader provided or reader is nil")
)

Predefined paackage errors

Functions

func GetFileContentType

func GetFileContentType(input io.Reader) (string, error)

GetFileContentType returns the content type of a file.

func GetFileContentTypeByBytes

func GetFileContentTypeByBytes(input []byte) (string, error)

GetFileContentTypeByBytes returns the content type of a file.

func GetFileExtension

func GetFileExtension(fileName string) string

Get the file extension. fileName string: the file name.

func GetFileNameWithoutExtension

func GetFileNameWithoutExtension(fileName string) string

Get the file name without extension. fileName string: the file name.

func GetFileSize

func GetFileSize(file io.ReadSeeker) (int64, error)

Get the file size. file io.ReadSeeker: the file to be uploaded.

func GetMaxFileParts

func GetMaxFileParts(file io.ReadSeeker, partSize int64) (int64, error)

Get max file parts can be if the file is split into parts with the given part size. The max file parts is 10000. file io.ReadSeeker: the file to be uploaded. partSize int64: the part size.

func NewS3Client

func NewS3Client(opt Options) (*s3.S3, error)

NewS3Client returns configured AWS S3 client

Types

type ACL

type ACL string

ACL permission

Predefined ACL permissions

func (ACL) String

func (a ACL) String() string

String returns the string representation of the ACL. This is required to satisfy the Stringer interface.

type CompletedPart

type CompletedPart interface {
	PartNumber() int64
	ETag() string
}

CompletedPart represents a part of a multipart upload.

type Interactor

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

Interactor struct

func New

func New(s3Client *s3.S3, bucket, fileEndpoint string) *Interactor

New is a factory function, returns a new instance of the storage interactor

func (*Interactor) AbortMultipartUpload

func (i *Interactor) AbortMultipartUpload(filename, uploadID string) error

AbortMultipartUpload aborts a multipart upload.

func (*Interactor) CompleteMultipartUpload

func (i *Interactor) CompleteMultipartUpload(filename, uploadID string, completedParts ...CompletedPart) error

CompleteMultipartUpload completes a multipart upload.

func (*Interactor) CreateMultipartUpload

func (i *Interactor) CreateMultipartUpload(filename, contentType string, acl ACL) (string, error)

Create multipart upload

func (*Interactor) Delete

func (i *Interactor) Delete(filepath string) error

Delete file from the cloud storage

func (*Interactor) Download

func (i *Interactor) Download(filepath string) (io.ReadCloser, *string, error)

Download file from the cloud storage

func (*Interactor) FileURL

func (i *Interactor) FileURL(filepath string) string

FileURL return public url for a file

func (*Interactor) Upload

func (i *Interactor) Upload(file []byte, filepath string, acl ACL, contentType string) error

Upload file to the cloud storage

func (*Interactor) UploadPart

func (i *Interactor) UploadPart(filename, uploadID string, data []byte, partNum, totalParts int64) (CompletedPart, error)

Upload uploads a file to S3. If partNum is equal to totalParts, the file is considered complete and the multipart upload is completed.

type Options

type Options struct {
	Key            string
	Secret         string
	Endpoint       string
	Region         string
	ForcePathStyle bool
	DisableSSL     bool
}

Options struct

Jump to

Keyboard shortcuts

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