http/upload
Documentation
- source: http/upload.ts
Overview
Classes
Upload
isMultipartContent()
Checks if the current incoming HTTP request contains multipart content (e.g., from an HTML form with `enctype="multipart/form-data"`).
tsstatic isMultipartContent(): boolean;Returns
- Type:
boolean- Description: True if the request is multipart, false otherwise.
parseRequest()
Parses the incoming multipart request content into a collection of file items. This operation typically consumes the request body.
tsstatic parseRequest(): FileItems;Returns
- Type:
FileItems- Description: A FileItems object representing all parts (files and form fields) of the request.
FileItems
get()
Retrieves a specific item (file or form field) by its index in the collection.
tsget(index: number): FileItem;
Parameter Type Description indexnumberThe zero-based index of the item. Returns
- Type:
FileItem- Description: A FileItem object representing the item at the specified index.
size()
Returns the total number of items (files and form fields) in the collection.
tssize(): number;Returns
- Type:
number- Description: The size of the collection.
FileItem
getName()
For a file upload, returns the original filename as reported by the client. For a regular form field, this is typically null or undefined.
tsgetName(): string;Returns
- Type:
string- Description: The original filename string.
getContentType()
Returns the MIME type of the uploaded file or content part.
tsgetContentType(): string;Returns
- Type:
string- Description: The content type string (e.g., 'image/png', 'text/plain').
isEmpty()
Checks if the uploaded item is empty (e.g., a file upload with zero bytes).
tsisEmpty(): boolean;Returns
- Type:
boolean- Description: True if the item is empty, false otherwise.
getSize()
Returns the size of the uploaded item in bytes.
tsgetSize(): number;Returns
- Type:
number- Description: The size as a number.
getBytes()
Retrieves the content of the file item as a JavaScript array of bytes. This uses a utility (`Bytes.toJavaScriptBytes`) to convert the native Java byte array.
tsgetBytes(): void;Returns
- Type:
void- Description: An array of bytes (`any[]`).
getBytesNative()
Retrieves the content of the file item as the native Java byte array.
tsgetBytesNative(): void;Returns
- Type:
void- Description: The native byte array (`any[]`).
getText()
Retrieves the content of the file item as a string. Note: This assumes the content is text and may not handle all encodings correctly. It relies on JavaScript's `String.fromCharCode.apply` for conversion.
tsgetText(): string;Returns
- Type:
string- Description: The content as a string.
getInputStream()
Gets an input stream for reading the content of the file item. This is useful for handling large files without loading the entire content into memory.
tsgetInputStream(): InputStream;Returns
- Type:
InputStream- Description: An InputStream object wrapping the native input stream.
