Closed talski closed 3 years ago
Hi, you can use wild storage and temporary directory, then in the controller move the file to the permanent storage directory
@Post('load')
@FormDataRequest({ storage: FileSystemStoredFile })
async getHello(@Body() attachmentsDto: AttachmentsDto, @Param() params: any, @Req() req): Promise<void> {
const user = req.user as User;
const storageDirPath = path.resolve(__dirname, 'attachments', user.tenant, 'questions', params.id, 'answers', user.id);
for (let file of attachmentsDto.attachments) {
fs.mkdirSync(storageDirPath, { recursive: true });
/** move file from temp folder to the permanent storage directory **/
fs.renameSync(file.path, path.resolve(storageDirPath, `${uuid()}-${file.originalName}`));
}
}