I am newbie in backend especially nodejs, I am using nestjs as framework. I want to make the name of my uploaded file https://mydomain/files/example-image.png
, but I get an error like this:
Error: ENOENT: no such file or directory,
open 'C:\***\***\***\nestjs-learning\files\http:\localhost:3001\files\9795f8f8147410d8fa07a4de5a92e0678.png'
and here is my code to name the file:
FileInterceptor('image', {
storage: diskStorage({
destination: './files',
filename: (req, file, cb) => {
const randomName = Array(32)
.fill(null)
.map(() => Math.round(Math.random() * 16).toString(16))
.join('');
return cb(null, `http://localhost:3001/files/${randomName}${extname(file.originalname)}`);
},
}),
}),
Is this way wrong? Is there a specific way to name the file? Please help me solve this.