upload

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionNotFound  = errors.New("upload session not found")
	ErrSessionExpired   = errors.New("upload session expired")
	ErrSessionCompleted = errors.New("upload session already completed")
	ErrInvalidChunk     = errors.New("invalid chunk index")
	ErrChunkExists      = errors.New("chunk already received")
	ErrFileTooLarge     = errors.New("file exceeds maximum allowed size")
	ErrInvalidChunkSize = errors.New("invalid chunk size")
	ErrChunkTooLarge    = errors.New("chunk exceeds declared chunk size")
	ErrUploadOverflow   = errors.New("chunk would exceed declared total size")
	ErrInvalidOffset    = errors.New("invalid upload offset")
)

Functions

This section is empty.

Types

type Manager

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

Manager handles upload sessions

func NewManager

func NewManager(tempDir string, sessionTTL time.Duration, maxUploadSize int64, log *logger.Logger) *Manager

NewManager creates a new upload manager

func (*Manager) Cancel

func (m *Manager) Cancel(sessionID string) error

Cancel cancels an upload session and cleans up

func (*Manager) CleanupSession

func (m *Manager) CleanupSession(sessionID string) error

CleanupSession removes a session after the file has been moved to its destination

func (*Manager) GetMissingChunks

func (m *Manager) GetMissingChunks(sessionID string) ([]int32, error)

GetMissingChunks returns the list of chunk indices that haven't been received

func (*Manager) GetSession

func (m *Manager) GetSession(id string) (*Session, error)

GetSession retrieves a session by ID

func (*Manager) GetSessionStatus

func (m *Manager) GetSessionStatus(sessionID string) (bytesReceived int64, totalBytes int64, chunksReceived int32, totalChunks int32, completed bool, tempPath string, err error)

GetSessionStatus returns the status of a session

func (*Manager) GetTempPath

func (m *Manager) GetTempPath(sessionID string) (string, string, error)

GetTempPath returns the temp file path for a completed session

func (*Manager) InitSession

func (m *Manager) InitSession(filename string, totalSize int64, chunkSize int32) (*Session, error)

InitSession creates a new upload session

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the manager and cleans up all sessions

func (*Manager) WriteChunk

func (m *Manager) WriteChunk(sessionID string, chunkIndex int32, data []byte) (completed bool, err error)

WriteChunk writes a chunk to the session's temp file

func (*Manager) WriteStream

func (m *Manager) WriteStream(sessionID string, r io.Reader, offset int64) (bytesWritten int64, completed bool, err error)

Writes data from a reader to the session file starting at the given offset

type Session

type Session struct {
	ID             string
	Filename       string
	TotalSize      int64
	ChunkSize      int32
	TotalChunks    int32
	ReceivedChunks map[int32]bool
	BytesReceived  int64
	TempPath       string
	ExpiresAt      time.Time
	Completed      bool
	// contains filtered or unexported fields
}

Session represents an active upload session

Jump to

Keyboard shortcuts

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