Description
Currently, the UploadedFile class in @h3ravel/http only provides minimal functionality via:
createFromBase()
moveTo()
To achieve feature parity with modern frameworks and provide developers with a complete set of file handling utilities, this class should be extended with additional methods and properties.
Goal
Enhance the UploadedFile class to include robust file management and inspection methods, covering file storage, retrieval, metadata, and validation.
Proposed Additions
Existing
createFromBase()
moveTo()
New Methods
path(): string — Returns the full temporary or stored file path.
extension(): string — Returns the file extension.
hashName(path?: string): string — Generates a unique hash-based filename.
dimensions(): Promise<{ width: number; height: number }> — Gets image dimensions (for image files).
fake(): UploadedFile — Generates a fake file instance (for testing).
store(path: string, options?: StoreOptions): Promise<string> — Stores the file in a given directory.
storePublicly(path: string, options?: StoreOptions): Promise<string> — Stores file in a public location.
storePubliclyAs(path: string, name: string, options?: StoreOptions): Promise<string> — Stores public file with a custom name.
storeAs(path: string, name: string, options?: StoreOptions): Promise<string> — Stores file with a specified name.
get(): Buffer | Promise<Buffer> — Reads the file content.
clientExtension(): string — Returns the client-provided file extension.
getClientMimeType(): string — Returns the MIME type reported by the client.
getError(): number | null — Returns any upload error code.
isValid(): boolean — Checks if the uploaded file is valid.
move(destination: string, name?: string): Promise<string> — Moves file to a given destination.
parseFilesize(size: number): string — Converts a size in bytes to a human-readable format.
getErrorMessage(): string | null — Returns a human-readable upload error message.
Tasks
- Review the current implementation of UploadedFile.
- Define the StoreOptions interface (e.g. { visibility?: 'private' | 'public'; disk?: string }).
- Implement all proposed methods.
- Ensure file operations integrate with the filesystem abstraction (Flydrive integration if available).
- Add helper imports for mime detection and image dimension extraction (e.g. image-size, mime-types).
- Write unit tests for all new methods.
- Document each method and property with JSDoc annotations.
Acceptance Criteria
Difficulty
Advanced
Description
Currently, the UploadedFile class in @h3ravel/http only provides minimal functionality via:
createFromBase()moveTo()To achieve feature parity with modern frameworks and provide developers with a complete set of file handling utilities, this class should be extended with additional methods and properties.
Goal
Enhance the UploadedFile class to include robust file management and inspection methods, covering file storage, retrieval, metadata, and validation.
Proposed Additions
Existing
createFromBase()moveTo()New Methods
path(): string— Returns the full temporary or stored file path.extension(): string— Returns the file extension.hashName(path?: string): string— Generates a unique hash-based filename.dimensions(): Promise<{ width: number; height: number }>— Gets image dimensions (for image files).fake(): UploadedFile— Generates a fake file instance (for testing).store(path: string, options?: StoreOptions): Promise<string>— Stores the file in a given directory.storePublicly(path: string, options?: StoreOptions): Promise<string>— Stores file in a public location.storePubliclyAs(path: string, name: string, options?: StoreOptions): Promise<string>— Stores public file with a custom name.storeAs(path: string, name: string, options?: StoreOptions): Promise<string>— Stores file with a specified name.get(): Buffer | Promise<Buffer>— Reads the file content.clientExtension(): string— Returns the client-provided file extension.getClientMimeType(): string— Returns the MIME type reported by the client.getError(): number | null— Returns any upload error code.isValid(): boolean— Checks if the uploaded file is valid.move(destination: string, name?: string): Promise<string>— Moves file to a given destination.parseFilesize(size: number): string— Converts a size in bytes to a human-readable format.getErrorMessage(): string | null— Returns a human-readable upload error message.Tasks
Acceptance Criteria
Difficulty
Advanced