Versions in this module Expand all Collapse all v0 v0.1.0 Nov 1, 2024 Changes in this version + const UploadLengthDeferred + var DefaultCorsConfig = CorsConfig + var ErrConnectionReset = NewError("ERR_CONNECTION_RESET", "TCP connection reset by peer", ...) + var ErrFileLocked = NewError("ERR_UPLOAD_LOCKED", "file currently locked", http.StatusLocked) + var ErrInvalidConcat = NewError("ERR_INVALID_CONCAT", "invalid Upload-Concat header", http.StatusBadRequest) + var ErrInvalidContentType = NewError("ERR_INVALID_CONTENT_TYPE", "missing or invalid Content-Type header", ...) + var ErrInvalidOffset = NewError("ERR_INVALID_OFFSET", "missing or invalid Upload-Offset header", ...) + var ErrInvalidUploadDeferLength = NewError("ERR_INVALID_UPLOAD_LENGTH_DEFER", "invalid Upload-Defer-Length header", ...) + var ErrInvalidUploadLength = NewError("ERR_INVALID_UPLOAD_LENGTH", "missing or invalid Upload-Length header", ...) + var ErrLockTimeout = NewError("ERR_LOCK_TIMEOUT", "failed to acquire lock before timeout", ...) + var ErrMaxSizeExceeded = NewError("ERR_MAX_SIZE_EXCEEDED", "maximum size exceeded", ...) + var ErrMismatchOffset = NewError("ERR_MISMATCHED_OFFSET", "mismatched offset", http.StatusConflict) + var ErrModifyFinal = NewError("ERR_MODIFY_FINAL", "modifying a final upload is not allowed", ...) + var ErrNotFound = NewError("ERR_UPLOAD_NOT_FOUND", "upload not found", http.StatusNotFound) + var ErrNotImplemented = NewError("ERR_NOT_IMPLEMENTED", "feature not implemented", http.StatusNotImplemented) + var ErrOriginNotAllowed = NewError("ERR_ORIGIN_NOT_ALLOWED", "request origin is not allowed", ...) + var ErrReadTimeout = NewError("ERR_READ_TIMEOUT", "timeout while reading request body", ...) + var ErrServerShutdown = NewError("ERR_SERVER_SHUTDOWN", ...) + var ErrSizeExceeded = NewError("ERR_UPLOAD_SIZE_EXCEEDED", "upload's size exceeded", ...) + var ErrUnexpectedEOF = NewError("ERR_UNEXPECTED_EOF", "server expected to receive more bytes", ...) + var ErrUnsupportedVersion = NewError("ERR_UNSUPPORTED_VERSION", ...) + var ErrUploadInterrupted = NewError("ERR_UPLOAD_INTERRUPTED", ...) + var ErrUploadLengthAndUploadDeferLength = NewError("ERR_AMBIGUOUS_UPLOAD_LENGTH", ...) + var ErrUploadNotFinished = NewError("ERR_UPLOAD_NOT_FINISHED", "one of the partial uploads is not finished", ...) + var ErrUploadRejectedByServer = NewError("ERR_UPLOAD_REJECTED", "upload creation has been rejected by server", ...) + var ErrUploadStoppedByServer = NewError("ERR_UPLOAD_STOPPED", "upload has been stopped by server", ...) + func ParseMetadataHeader(header string) map[string]string + func SerializeMetadataHeader(meta map[string]string) string + type ConcatableUpload interface + ConcatUploads func(ctx context.Context, partialUploads []Upload) error + type ConcaterDataStore interface + AsConcatableUpload func(upload Upload) ConcatableUpload + type Config struct + AcquireLockTimeout time.Duration + BasePath string + Cors *CorsConfig + DisableDownload bool + DisableTermination bool + EnableExperimentalProtocol bool + GracefulRequestCompletionTimeout time.Duration + Logger *slog.Logger + MaxSize int64 + NetworkTimeout time.Duration + NotifyCompleteUploads bool + NotifyCreatedUploads bool + NotifyTerminatedUploads bool + NotifyUploadProgress bool + PreFinishResponseCallback func(hook HookEvent) (HTTPResponse, error) + PreUploadCreateCallback func(hook HookEvent) (HTTPResponse, FileInfoChanges, error) + RespectForwardedHeaders bool + StoreComposer *StoreComposer + UploadProgressInterval time.Duration + type CorsConfig struct + AllowCredentials bool + AllowHeaders string + AllowMethods string + AllowOrigin *regexp.Regexp + Disable bool + ExposeHeaders string + MaxAge string + type DataStore interface + GetUpload func(ctx context.Context, id string) (upload Upload, err error) + NewUpload func(ctx context.Context, info FileInfo) (upload Upload, err error) + type Error struct + ErrorCode string + HTTPResponse HTTPResponse + Message string + func NewError(errCode string, message string, statusCode int) Error + func (e Error) Error() string + func (e1 Error) Is(target error) bool + type ErrorsTotalMap struct + func (e *ErrorsTotalMap) Load() map[ErrorsTotalMapEntry]*uint64 + type ErrorsTotalMapEntry struct + ErrorCode string + StatusCode int + type FileInfo struct + ID string + IsFinal bool + IsPartial bool + MetaData MetaData + Offset int64 + PartialUploads []string + Size int64 + SizeIsDeferred bool + Storage map[string]string + func (f FileInfo) StopUpload(response HTTPResponse) + type FileInfoChanges struct + ID string + MetaData MetaData + Storage map[string]string + type HTTPHeader map[string]string + type HTTPRequest struct + Header http.Header + Method string + RemoteAddr string + URI string + type HTTPResponse struct + Body string + Header HTTPHeader + StatusCode int + func (resp1 HTTPResponse) MergeWith(resp2 HTTPResponse) HTTPResponse + type Handler struct + func NewHandler(config Config) (*Handler, error) + type HookEvent struct + Context context.Context + HTTPRequest HTTPRequest + Upload FileInfo + type LengthDeclarableUpload interface + DeclareLength func(ctx context.Context, length int64) error + type LengthDeferrerDataStore interface + AsLengthDeclarableUpload func(upload Upload) LengthDeclarableUpload + type Lock interface + Lock func(ctx context.Context, requestUnlock func()) error + Unlock func() error + type Locker interface + NewLock func(id string) (Lock, error) + type MetaData map[string]string + type Metrics struct + BytesReceived *uint64 + ErrorsTotal *ErrorsTotalMap + RequestsTotal map[string]*uint64 + UploadsCreated *uint64 + UploadsFinished *uint64 + UploadsTerminated *uint64 + type StoreComposer struct + Concater ConcaterDataStore + Core DataStore + LengthDeferrer LengthDeferrerDataStore + Locker Locker + Terminater TerminaterDataStore + UsesConcater bool + UsesLengthDeferrer bool + UsesLocker bool + UsesTerminater bool + func NewStoreComposer() *StoreComposer + func (store *StoreComposer) Capabilities() string + func (store *StoreComposer) UseConcater(ext ConcaterDataStore) + func (store *StoreComposer) UseCore(core DataStore) + func (store *StoreComposer) UseLengthDeferrer(ext LengthDeferrerDataStore) + func (store *StoreComposer) UseLocker(ext Locker) + func (store *StoreComposer) UseTerminater(ext TerminaterDataStore) + type TerminatableUpload interface + Terminate func(ctx context.Context) error + type TerminaterDataStore interface + AsTerminatableUpload func(upload Upload) TerminatableUpload + type UnroutedHandler struct + CompleteUploads chan HookEvent + CreatedUploads chan HookEvent + Metrics Metrics + TerminatedUploads chan HookEvent + UploadProgress chan HookEvent + func NewUnroutedHandler(config Config) (*UnroutedHandler, error) + func (handler *UnroutedHandler) DelFile(w http.ResponseWriter, r *http.Request) + func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) + func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) + func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler + func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request) + func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) + func (handler *UnroutedHandler) PostFileV2(w http.ResponseWriter, r *http.Request) + func (handler *UnroutedHandler) SupportedExtensions() string + type Upload interface + FinishUpload func(ctx context.Context) error + GetInfo func(ctx context.Context) (FileInfo, error) + GetReader func(ctx context.Context) (io.ReadCloser, error) + WriteChunk func(ctx context.Context, offset int64, src io.Reader) (int64, error)