hi 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)}`);
},
}),
}),
这个方法是错误的吗?,有一个具体的方法来命名这文件?有人请帮助我解决这个问题
1条答案
按热度按时间6fe3ivhb1#
问题是你在文件名中添加url路径试试这个