Documentation ¶
Index ¶
- Variables
- func GetFileContentType(input io.Reader) (string, error)
- func GetFileContentTypeByBytes(input []byte) (string, error)
- func GetFileExtension(fileName string) string
- func GetFileNameWithoutExtension(fileName string) string
- func GetFileSize(file io.ReadSeeker) (int64, error)
- func GetMaxFileParts(file io.ReadSeeker, partSize int64) (int64, error)
- func NewS3Client(opt Options) (*s3.S3, error)
- type ACL
- type CompletedPart
- type Interactor
- func (i *Interactor) AbortMultipartUpload(filename, uploadID string) error
- func (i *Interactor) CompleteMultipartUpload(filename, uploadID string, completedParts ...CompletedPart) error
- func (i *Interactor) CreateMultipartUpload(filename, contentType string, acl ACL) (string, error)
- func (i *Interactor) Delete(filepath string) error
- func (i *Interactor) Download(filepath string) (io.ReadCloser, *string, error)
- func (i *Interactor) FileURL(filepath string) string
- func (i *Interactor) Upload(file []byte, filepath string, acl ACL, contentType string) error
- func (i *Interactor) UploadPart(filename, uploadID string, data []byte, partNum, totalParts int64) (CompletedPart, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
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 ¶
GetFileContentType returns the content type of a file.
func GetFileContentTypeByBytes ¶
GetFileContentTypeByBytes returns the content type of a file.
func GetFileExtension ¶
Get the file extension. fileName string: the file name.
func GetFileNameWithoutExtension ¶
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.
Types ¶
type ACL ¶
type ACL string
ACL permission
const ( Public ACL = s3.ObjectCannedACLPublicRead Private ACL = s3.ObjectCannedACLPrivate )
Predefined ACL permissions
type CompletedPart ¶
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) 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.