I set option @ServerSetings
{
multer: {
storage: handleStorage(),
}
With handleStore function will return multer.StorageEngine, but I when upload is error and crash node
Hello @thanhchuongitc
Can you give a repository with a reproductible example please.
I haven't enough information to reproduct your problem.
See you
Romain
The same thing happened to me, I had to pass the storage function directly to the controller, because as a global function it doesn't work. I guess it should be fixed, while you can do it on the controller:
import { MulterOptions, MultipartFile } from '@tsed/multipartfiles'
import { diskStorage } from 'multer';
const storage = diskStorage({
destination: function (req, file, cb) {
cb(null, './public/uploads/profiles')
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
});
@Post('/upload/:id')
@Description('Upload image profile by user ID')
@MulterOptions({ storage: storage })
async upload (@MultipartFile('image') image, @PathParams('id') id): Promise<any> {
const user = await this.userRepository.findOne(id);
if (!user) {
throw new NotFound('Not user found')
}
user.image = '/uploads/profiles/' + image.originalname;
return this.userRepository.save(user);
}
The same thing happened to me, I had to pass the storage function directly to the controller, because as a global function it doesn't work. I guess it should be fixed, while you can do it on the controller:
import { MulterOptions, MultipartFile } from '@tsed/multipartfiles' import { diskStorage } from 'multer'; const storage = diskStorage({ destination: function (req, file, cb) { cb(null, './public/uploads/profiles') }, filename: function (req, file, cb) { cb(null, file.originalname) } }); @Post('/upload/:id') @Description('Upload image profile by user ID') @MulterOptions({ storage: storage }) async upload (@MultipartFile('image') image, @PathParams('id') id): Promise<any> { const user = await this.userRepository.findOne(id); if (!user) { throw new NotFound('Not user found') } user.image = '/uploads/profiles/' + image.originalname; return this.userRepository.save(user); }
Thank you, I fixed it
I keep this issue open. I'll fix this ASAP
:tada: This issue has been resolved in version 5.44.14 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Fixed :)
Most helpful comment
Fixed :)