@nasriya/hypercloud
Version:
Nasriya HyperCloud is a lightweight Node.js HTTP2 framework.
62 lines (61 loc) • 2.72 kB
TypeScript
import { StorageSize } from '../../docs/docs';
import UploadLimits from './assets/limits';
declare class Uploads {
#private;
constructor();
/**
* Gets the directory where uploads are stored.
* If the directory does not exist, it will be created.
* @returns {string} The directory path.
*/
get directory(): string;
/**
* Sets the directory where uploads are stored.
* Validates if the directory exists and creates it if necessary.
* @param {string} dir - The directory path to set.
*/
set directory(dir: string);
/**
* Gets the maximum file size allowed for uploads.
* @returns {number} The maximum file size in bytes.
*/
get maxFileSize(): number;
/**
* Sets the maximum file size allowed for uploads.
* Converts the provided value to a numerical limit if necessary.
* @param {number | StorageSize} value - The maximum file size to set.
*/
set maxFileSize(value: number | StorageSize);
/**
* Manages and configures file uploads, including setting size limits, directories, and MIME type restrictions.
*
* The `uploads` instance provides a comprehensive interface for handling file uploads on the server. It allows you to define maximum file sizes for different types of uploads, configure the upload directory, and set specific limits based on MIME types. This utility ensures that your server handles file uploads efficiently and securely, with customizable parameters to suit your needs.
*
* **Example Usage:**
*
* ```js
* // Set the directory where uploads will be stored
* server.uploads.directory = '/path/to/uploads';
*
* // Set the maximum file size for uploads to 50 MB
* server.uploads.maxFileSize = { value: 50, unit: 'MB' };
*
* // Set the maximum file size for images to 10 MB
* server.uploads.limits.images = { value: 10, unit: 'MB' };
*
* // Retrieve the current maximum file size for images
* const maxImageSize = server.uploads.limits.images;
*
* // Set a specific limit for PDF files
* server.uploads.limits.mime.set('application/pdf', { value: 5, unit: 'MB' });
* ```
*
* **Properties:**
*
* - **directory**: Gets or sets the directory where uploads are stored. If the directory does not exist, it will be created automatically.
* - **maxFileSize**: Gets or sets the maximum file size allowed for uploads, either as a number in bytes or as a `StorageSize` object.
* - **limits**: Provides access to upload size limits for file streams, images, videos, and specific MIME types.
*/
get limits(): UploadLimits;
}
export default Uploads;