@travetto/web-upload
v7.1.4
Published
Provides integration between the travetto asset and web module.
Readme
Web Upload Support
Provides integration between the travetto asset and web module.
Install: @travetto/web-upload
npm install @travetto/web-upload
# or
yarn add @travetto/web-uploadThis module provides a clean and direct mechanism for processing uploads, built upon @fastify/busboy. The module also provides some best practices with respect to temporary file management.
Once the files are uploaded, they are exposed via Endpoint parameters using the @Upload decorator. This decorator requires the related field type to be a standard Buffer object, or a FileMap.
A simple example:
Code: Web controller with upload support
import { Controller, Post, Get } from '@travetto/web';
import { type FileMap, Upload } from '@travetto/web-upload';
@Controller('/simple')
export class Simple {
@Get('/age')
getAge() {
return { age: 50 };
}
@Post('/age')
getPage() {
return { age: 20 };
}
/**
* @param file A file to upload
*/
@Post('/file')
loadFile(@Upload() upload: File) {
return upload;
}
/**
* @param uploads A map of files that were uploaded
*/
@Post('/files')
async loadFiles(@Upload() uploads: FileMap) {
for (const [, upload] of Object.entries(uploads)) {
return upload;
}
}
}