fileupload

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package fileupload implements the functions, types, and interfaces for the module.

Package fileupload implements the functions, types, and interfaces for the module.

Package fileupload implements the functions, types, and interfaces for the module.

Package fileupload implements the functions, types, and interfaces for the module.

Index

Constants

View Source
const (
	ModTimeFormat = "Mon, 02 Jan 2006 15:04:05 MST"
)

Variables

View Source
var (
	ErrNoFile         = errors.New("no file provided")
	ErrInvalidRequest = errors.New("invalid request")
	ErrUploadFailed   = errors.New("upload failed")
)

Functions

func GenerateContentHash added in v0.1.10

func GenerateContentHash(file io.Reader) (string, error)

GenerateContentHash generates a content-addressed hash for a file.

func GenerateFileNameHash added in v0.1.10

func GenerateFileNameHash(data string) string

func GenerateRandomHash added in v0.1.10

func GenerateRandomHash() string

Types

type BuildSetting added in v0.1.10

type BuildSetting = func(o *uploadBuilder)

func WithBufferSize added in v0.1.10

func WithBufferSize(size int) BuildSetting

func WithHash added in v0.1.10

func WithHash(hash func(name string) string) BuildSetting

func WithURI added in v0.1.10

func WithURI(uri string) BuildSetting

type Builder added in v0.1.10

type Builder interface {
	NewBuffer() []byte
	Free([]byte)
}

Builder defines the interface for creating uploaders and downloaders

func NewBuilder added in v0.1.10

func NewBuilder(ss ...BuildSetting) Builder

NewBuilder creates a new httpBuilder with the given options

type Downloader added in v0.1.10

type Downloader interface {
	// GetFileHeader retrieves the file header after the file has been downloaded.
	GetFileHeader(ctx context.Context) (FileHeader, error)
	// DownloadFile downloads the file first and then retrieves the header.
	DownloadFile(ctx context.Context) (io.Reader, error)
	// Finalize finalizes the download process.
	Finalize(ctx context.Context, resp UploadResponse) error
}

func NewDownloader added in v0.1.10

func NewDownloader(req *http.Request, resp http.ResponseWriter, ss ...BuildSetting) (Downloader, error)

type FileHeader

type FileHeader interface {
	// GetFilename returns the name of the file.
	GetFilename() string

	// GetSize returns the size of the file in bytes.
	GetSize() uint32

	// GetModTime returns the last modified time of the file as a string.
	GetModTime() uint32

	// GetModTimeString returns the last modified time of the file as a Unix timestamp.
	GetModTimeString() string

	// GetContentType returns the MIME type of the file.
	GetContentType() string

	// GetHeader returns a map of additional file headers.
	GetHeader() map[string]string

	// GetIsDir returns true if the file is a directory.
	GetIsDir() bool
}

FileHeader represents a file header with metadata.

type FileInfo

type FileInfo interface {
	fs.FileInfo
	ContentType() string
}

func ParseHeader added in v0.1.10

func ParseHeader(header FileHeader) FileInfo

func ParseMultipart added in v0.1.10

func ParseMultipart(header *multipart.FileHeader) FileInfo

type UploadResponse

type UploadResponse interface {
	// GetSuccess indicates whether the file upload was successful.
	GetSuccess() bool

	// GetHash returns the hash of the uploaded file.
	GetHash() string

	// GetPath returns the path where the file was uploaded.
	GetPath() string

	// GetSize returns the size of the uploaded file in bytes.
	GetSize() uint32

	// GetFailReason returns the failure reason of the file upload.
	GetFailReason() string
}

UploadResponse represents a response to a file upload request.

type Uploader

type Uploader interface {
	// SetFileHeader sets the file header after the file has been uploaded.
	SetFileHeader(ctx context.Context, header FileHeader) error
	// UploadFile uploads the file first and then sets the header.
	UploadFile(ctx context.Context, rd io.Reader) error
	// Finalize finalizes the upload process.
	Finalize(ctx context.Context) (UploadResponse, error)
}

func NewUploader added in v0.1.10

func NewUploader(ctx context.Context, ss ...BuildSetting) (Uploader, error)

Jump to

Keyboard shortcuts

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