I am making img converter (png,webp,jpg,etc)
- using multer to uplaod image and sharp to convert img
- very thing is going fine but when I unlink uploaded webp img an error shows up!
ERROR
Error: EBUSY: resource busy or locked, unlink 'public\uploads\Windows 101632682048612-.webp' at Object.unlinkSync (fs.js:1251:3) at Object.<anonymous> (D:\nodejs\webp\index.js:81:14) { errno: -4082, syscall: 'unlink', code: 'EBUSY', path: 'public\\uploads\\Windows 101632682048612-.webp' }
let outputFilePath = "public/converted/"+file.originalname.split('.').slice(0, -1).join('.') + "--converted." + format;
let path= sharp(file.path)
.toFile(outputFilePath, (err, info) => {
if (err) throw err;
// code to unlink file
try{
fs.unlinkSync(file.path)
}
catch(err){
console.log(err)
}
})
return path.options.fileOut;
}```