Documentation
¶
Index ¶
- Variables
- type DirectUploadToken
- type DirectWritableUploadFileStoreProvider
- type FileParameterUploadManager
- func (m *FileParameterUploadManager) AbortUploadSession(sessionToken string) error
- func (m *FileParameterUploadManager) CompleteUploadSession(sessionToken string) (int64, error)
- func (m *FileParameterUploadManager) StartUploadSession(uploadTokenID string, fileName string, totalSizeBytes int64) (*chunkedupload.ChunkSession, error)
- func (m *FileParameterUploadManager) SuggestedChunkSize() int64
- func (m *FileParameterUploadManager) WriteChunk(sessionToken string, offsetBytes int64, data []byte) (int64, error)
- type InPlaceUploadFileStoreProvider
- type JSONLineUploadFileVerifier
- type JobModeStore
- func (s *JobModeStore) GetCompletedResult(ctx context.Context, token UploadToken, req map[string]any) (UploadResult, error)
- func (s *JobModeStore) GetResult(token UploadToken, req map[string]any) (UploadResult, error)
- func (s *JobModeStore) GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
- type LocalFileUploadToken
- type LocalUploadFileStoreProvider
- func (l *LocalUploadFileStoreProvider) GetDestinationPath(token UploadToken) (string, error)
- func (l *LocalUploadFileStoreProvider) GetUploadToken(id string) UploadToken
- func (l *LocalUploadFileStoreProvider) Read(token UploadToken) (io.ReadCloser, error)
- func (l *LocalUploadFileStoreProvider) Write(token UploadToken, reader io.Reader) error
- type NopWaitUploadFileVerifier
- type Store
- type UploadFileStore
- func (s *UploadFileStore) GetCompletedResult(ctx context.Context, token UploadToken, req map[string]any) (UploadResult, error)
- func (s *UploadFileStore) GetResult(token UploadToken, req map[string]any) (UploadResult, error)
- func (s *UploadFileStore) GetStoreProvider() UploadFileStoreProvider
- func (s *UploadFileStore) GetTokenByID(id string) (UploadToken, error)
- func (s *UploadFileStore) GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
- func (s *UploadFileStore) NotifyFileUploaded(token UploadToken) error
- func (s *UploadFileStore) SetResultOnCompletedUpload(token UploadToken, uploadError error) error
- func (s *UploadFileStore) SetResultOnStartingUpload(token UploadToken) error
- type UploadFileStoreProvider
- type UploadFileVerifier
- type UploadResult
- type UploadStatus
- type UploadToken
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUploadTokenNotFound is returned when an upload token ID is unknown to the upload store. ErrUploadTokenNotFound = errors.New("upload token not found") )
Functions ¶
This section is empty.
Types ¶
type DirectUploadToken ¶
type DirectUploadToken struct {
// ID identifies the file location uploaded to this server directly.
ID string `json:"id"`
}
DirectUploadToken is a UploadToken for uploading the target file to API directly.
func (*DirectUploadToken) GetHash ¶
func (d *DirectUploadToken) GetHash() string
GetHash implements UploadToken.
func (*DirectUploadToken) GetID ¶
func (d *DirectUploadToken) GetID() string
GetID implements UploadToken.
func (*DirectUploadToken) GetType ¶
func (d *DirectUploadToken) GetType() string
GetType implements UploadToken.
type DirectWritableUploadFileStoreProvider ¶
type DirectWritableUploadFileStoreProvider interface {
// Write writes file data from the given reader to the file identified by token.
Write(token UploadToken, reader io.Reader) error
// GetDestinationPath returns the absolute file system path for storing the uploaded file.
GetDestinationPath(token UploadToken) (string, error)
}
DirectWritableUploadFileStoreProvider defines write operations for store providers.
type FileParameterUploadManager ¶ added in v0.58.2
type FileParameterUploadManager struct {
// contains filtered or unexported fields
}
FileParameterUploadManager manages chunked upload sessions for file form parameters.
func NewFileParameterUploadManager ¶ added in v0.58.2
func NewFileParameterUploadManager( uploadStore *UploadFileStore, chunkManager *chunkedupload.ChunkSessionManager, ) *FileParameterUploadManager
NewFileParameterUploadManager creates a new FileParameterUploadManager instance.
func (*FileParameterUploadManager) AbortUploadSession ¶ added in v0.58.2
func (m *FileParameterUploadManager) AbortUploadSession(sessionToken string) error
AbortUploadSession cancels and deletes any intermediate chunk files for the session.
func (*FileParameterUploadManager) CompleteUploadSession ¶ added in v0.58.2
func (m *FileParameterUploadManager) CompleteUploadSession(sessionToken string) (int64, error)
CompleteUploadSession finalizes the chunked session, persists the file into the store provider, and notifies the upload store that the file is ready for verification and task consumption.
func (*FileParameterUploadManager) StartUploadSession ¶ added in v0.58.2
func (m *FileParameterUploadManager) StartUploadSession(uploadTokenID string, fileName string, totalSizeBytes int64) (*chunkedupload.ChunkSession, error)
StartUploadSession starts a new chunked upload session for the given upload token ID.
func (*FileParameterUploadManager) SuggestedChunkSize ¶ added in v0.58.2
func (m *FileParameterUploadManager) SuggestedChunkSize() int64
SuggestedChunkSize returns the recommended chunk size in bytes.
func (*FileParameterUploadManager) WriteChunk ¶ added in v0.58.2
func (m *FileParameterUploadManager) WriteChunk(sessionToken string, offsetBytes int64, data []byte) (int64, error)
WriteChunk writes a single chunk payload at the specified byte offset for the session.
type InPlaceUploadFileStoreProvider ¶ added in v0.57.1
type InPlaceUploadFileStoreProvider struct{}
InPlaceUploadFileStoreProvider is an implementation of UploadFileStore that reads files in place.
func (*InPlaceUploadFileStoreProvider) GetUploadToken ¶ added in v0.57.1
func (i *InPlaceUploadFileStoreProvider) GetUploadToken(id string) UploadToken
GetUploadToken implements UploadFileStoreProvider.
func (*InPlaceUploadFileStoreProvider) Read ¶ added in v0.57.1
func (i *InPlaceUploadFileStoreProvider) Read(token UploadToken) (io.ReadCloser, error)
Read implements UploadFileStoreProvider.
type JSONLineUploadFileVerifier ¶
type JSONLineUploadFileVerifier struct {
MaxLineSizeInBytes int
}
func (*JSONLineUploadFileVerifier) Verify ¶
func (j *JSONLineUploadFileVerifier) Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
Verify implements UploadFileVerifier.
type JobModeStore ¶ added in v0.57.1
type JobModeStore struct {
// contains filtered or unexported fields
}
JobModeStore is a Store implementation for job mode. Job mode does not run the web server, so files cannot be uploaded from a browser; instead this store resolves file form inputs from local file paths given in the inspection request values.
func NewJobModeStore ¶ added in v0.57.1
func NewJobModeStore() *JobModeStore
NewJobModeStore creates a new JobModeStore.
func (*JobModeStore) GetCompletedResult ¶ added in v0.59.0
func (s *JobModeStore) GetCompletedResult(ctx context.Context, token UploadToken, req map[string]any) (UploadResult, error)
GetCompletedResult resolves and verifies the file synchronously for job mode.
func (*JobModeStore) GetResult ¶ added in v0.57.1
func (s *JobModeStore) GetResult(token UploadToken, req map[string]any) (UploadResult, error)
GetResult resolves the file for the given token from the local file path in the request values, verifies it, and returns a completed UploadResult. It returns an error when the token is unknown or no path was provided.
func (*JobModeStore) GetUploadToken ¶ added in v0.57.1
func (s *JobModeStore) GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
GetUploadToken issues a token for the given ID and records the form field ID and verifier so that GetResult can resolve the file later.
type LocalFileUploadToken ¶ added in v0.57.1
type LocalFileUploadToken struct {
// FilePath identifies the file location uploaded to this server locally.
FilePath string `json:"filepath"`
}
LocalFileUploadToken is a UploadToken for uploading local files via file path.
func (*LocalFileUploadToken) GetHash ¶ added in v0.57.1
func (l *LocalFileUploadToken) GetHash() string
GetHash implements UploadToken.
func (*LocalFileUploadToken) GetID ¶ added in v0.57.1
func (l *LocalFileUploadToken) GetID() string
GetID implements UploadToken.
func (*LocalFileUploadToken) GetType ¶ added in v0.57.1
func (l *LocalFileUploadToken) GetType() string
GetType implements UploadToken.
type LocalUploadFileStoreProvider ¶
type LocalUploadFileStoreProvider struct {
// contains filtered or unexported fields
}
LocalUploadFileStoreProvider is an implementation of UploadFileStore that stores files in the local file system.
func NewLocalUploadFileStoreProvider ¶
func NewLocalUploadFileStoreProvider(directoryPath string) *LocalUploadFileStoreProvider
NewLocalUploadFileStoreProvider creates a new LocalUploadFileStoreProvider.
func (*LocalUploadFileStoreProvider) GetDestinationPath ¶ added in v0.58.2
func (l *LocalUploadFileStoreProvider) GetDestinationPath(token UploadToken) (string, error)
GetDestinationPath returns the local filesystem destination path for the given token.
func (*LocalUploadFileStoreProvider) GetUploadToken ¶
func (l *LocalUploadFileStoreProvider) GetUploadToken(id string) UploadToken
GetUploadToken implements UploadFileStoreProvider.
func (*LocalUploadFileStoreProvider) Read ¶
func (l *LocalUploadFileStoreProvider) Read(token UploadToken) (io.ReadCloser, error)
Read implements UploadFileStoreProvider.
func (*LocalUploadFileStoreProvider) Write ¶
func (l *LocalUploadFileStoreProvider) Write(token UploadToken, reader io.Reader) error
Write implements DirectWritableUploadFileStoreProvider.
type NopWaitUploadFileVerifier ¶
type NopWaitUploadFileVerifier struct {
// WaitTimeInMs is the time to wait before returning the veification result.
WaitTimeInMs int
// Error is the error returned from Verify function after waiting the WaitTimeInMs.
Error error
}
NopWaitUploadFileVerifier just waits the specified time without doing anything on the file.
func (*NopWaitUploadFileVerifier) Verify ¶
func (n *NopWaitUploadFileVerifier) Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
Verify implements UploadFileVerifier.
type Store ¶ added in v0.57.1
type Store interface {
GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
GetResult(token UploadToken, req map[string]any) (UploadResult, error)
// GetCompletedResult waits for asynchronous verification to complete if the file has been uploaded,
// or returns the current non-completed status immediately if upload transfer is still pending or in progress.
GetCompletedResult(ctx context.Context, token UploadToken, req map[string]any) (UploadResult, error)
}
Store is the store interface form tasks depend on. Server mode and job mode inject different implementations of it.
type UploadFileStore ¶
type UploadFileStore struct {
StoreProvider UploadFileStoreProvider
// contains filtered or unexported fields
}
UploadFileStore manages file uploads and coordinates non-blocking verification.
func NewUploadFileStore ¶
func NewUploadFileStore(storeProvider UploadFileStoreProvider) *UploadFileStore
NewUploadFileStore creates a new UploadFileStore.
func (*UploadFileStore) GetCompletedResult ¶ added in v0.59.0
func (s *UploadFileStore) GetCompletedResult(ctx context.Context, token UploadToken, req map[string]any) (UploadResult, error)
GetCompletedResult waits for any asynchronous verification to complete and returns the upload result.
func (*UploadFileStore) GetResult ¶
func (s *UploadFileStore) GetResult(token UploadToken, req map[string]any) (UploadResult, error)
GetResult returns the result of the upload with the given token.
func (*UploadFileStore) GetStoreProvider ¶ added in v0.58.2
func (s *UploadFileStore) GetStoreProvider() UploadFileStoreProvider
GetStoreProvider returns the underlying UploadFileStoreProvider.
func (*UploadFileStore) GetTokenByID ¶ added in v0.58.2
func (s *UploadFileStore) GetTokenByID(id string) (UploadToken, error)
GetTokenByID looks up an issued UploadToken by its string ID.
func (*UploadFileStore) GetUploadToken ¶
func (s *UploadFileStore) GetUploadToken(id string, verifier UploadFileVerifier, fieldID string) UploadToken
GetUploadToken returns the token to upload a file from the frontend.
func (*UploadFileStore) NotifyFileUploaded ¶ added in v0.58.2
func (s *UploadFileStore) NotifyFileUploaded(token UploadToken) error
NotifyFileUploaded records that a file upload has completed and resets any cached verification.
func (*UploadFileStore) SetResultOnCompletedUpload ¶
func (s *UploadFileStore) SetResultOnCompletedUpload(token UploadToken, uploadError error) error
SetResultOnCompletedUpload records the upload completion status and error.
func (*UploadFileStore) SetResultOnStartingUpload ¶
func (s *UploadFileStore) SetResultOnStartingUpload(token UploadToken) error
SetResultOnStartingUpload sets the upload status to Uploading.
type UploadFileStoreProvider ¶
type UploadFileStoreProvider interface {
// GetUploadToken generates an UploadToken for the given ID.
GetUploadToken(id string) UploadToken
// Read returns the io.ReadCloser to read the file with the given token.
// The caller MUST close the returned ReadCloser.
Read(token UploadToken) (io.ReadCloser, error)
}
UploadFileStoreProvider defines operations for reading uploaded files.
type UploadFileVerifier ¶
type UploadFileVerifier interface {
// Verify checks the file. This returns an error if invalid.
Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
}
UploadFileVerifier verifies uploaded files (e.g., file type checks).
type UploadResult ¶
type UploadResult struct {
// Token is an UploadToken associated with the file.
Token UploadToken
// StoreProvider provides the way of getting the uploaded file with the given token.
StoreProvider UploadFileStoreProvider
// Status is the current state of the upload.
Status UploadStatus
// UploadError contains any error that occurred during the upload process itself
UploadError error
// VerificationError contains any error returned by the UploadFileVerifier.
VerificationError error
// VerificationCount is the attempt count of the verification logic. This value is preventing the race condition in verification steps.
VerificationCount int
}
UploadResult holds the result of an upload operation.
func (*UploadResult) GetReader ¶
func (r *UploadResult) GetReader() (io.ReadCloser, error)
GetReader returns an io.ReadCloser for reading the uploaded file. The caller MUST close the returned ReadCloser.
type UploadStatus ¶
type UploadStatus int
UploadStatus represents the status of an upload (Waiting, Uploading, Verifying, or Completed).
const ( // UploadStatusWaiting indicates this file is not yet uploaded or in progress of upload. UploadStatusWaiting UploadStatus = 0 // UploadStatusUploading indicates this file is being uploaded. UploadStatusUploading UploadStatus = 1 // UploadStatusVerifying indicates the file was uploaded and is currently being verified. UploadStatusVerifying UploadStatus = 2 // UploadStatusCompleted indicates the file upload and verification process has finished. UploadStatusCompleted UploadStatus = 3 )
type UploadToken ¶
type UploadToken interface {
// GetType returns the type of token specifying the methods to upload the file.
GetType() string
// GetID returns the unique identifier of upload files.
GetID() string
// GetHash returns a unique string calculated from all the field of the implementation.
// This must be calculated from ALL the field because this is for checking if 2 instances are identical.
GetHash() string
}
UploadToken is the type given to the frontend to receive the file. This currently exects files are uploaded to API directly, but in future this may support the upload using signed URLs as well. All token implements this type must be serializable as JSON.