我一直在尝试使用Sharp模块来调整在我的电子商务项目中为产品上传的图像的大小。请参阅代码段。在将尖锐的驻留代码片段插入mycode中时,我需要帮助
const create = (req,
res, next) => {
let form = new.
formidable.
IncomingForm()
form.keepExtensions.
= true
form.parse(req,
async (err, fields,
files) => {
if (err) {
return.
res.status(400).json({
message: "Image could not be uploaded"
})
}
let product = new Product(fields)
product.shop= req.shop
if(files.image){
product.image.data = fs.readFileSync(files.image.path)
product.image.contentType = files.image.type
}
try {
let result = await product.save()
res.json(result)
} catch (err){
return res.status(400).json({
error: errorHandler.getErrorMessage(err)
})
}
})
}