I was wondering if you could provide an example on how to use the @UploadedFile decorator. I'm unsure how I should be configuring multer before invoking the decorater. Appreciate any tips.
Thanks,
Alex
This is how I use it:
@Post("/:id/photos")
async uploadPhoto( @UploadedFile("file") file: any, @BodyParam("photo") photo: Photograph) {
//photo is a Form parameter
if (photo) {
this.createDirectoryForCollection(photo.photoCollectionId);
photo = await this.photoRepository.persist(photo);
photo.preview = this.createPreviewUrl(photo.photoCollectionId, photo.id);
photo.source = this.createFullsizeUrl(photo.photoCollectionId, photo.id);
//This is the file
let buffer: Buffer = file.buffer;
await this.moveImage(buffer, photo.source);
console.log(photo);
return this.photoRepository.persist(photo);
}
}
Hope this helps
@AleskiWeb there is uploadOptions in decorator, you can use it for example this way:
```ts
@UploadedFiles("files", { uploadOptions: FILE_UPLOAD_OPTIONS }) files: any[]
```ts
export const FILE_UPLOAD_OPTIONS = {
storage: multer.diskStorage({
destination: (req: any, file: any, cb: any) => { ...
},
filename: (req: any, file: any, cb: any) => { ...
}
}),
fileFilter: (req: any, file: any, cb: any) => { ...
},
limits: {
fieldNameSize: 255,
fileSize: 1024 * 1024 * 2
}
}
Could you also provide the code of the client how to send a file?
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Could you also provide the code of the client how to send a file?