【发布时间】:2022-05-10 23:39:58
【问题描述】:
我正在使用 cloudinary 进行图像上传和存储。当我尝试上传一个简单的 JPG 文件时,它给了我以下错误:
"PayloadTooLargeError: request entity too large"
{
message: 'request entity too large',
expected: 1127957,
length: 1127957,
limit: 102400,
type: 'entity.too.large'
}
以下是我的后端代码:
cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.CLOUD_API_KEY,
api_secret: process.env.CLOUD_API_SECRET
})
exports.uploadImage = catchAsync(async(req, res, next) => {
cloudinary.uploader.upload(req.body.img)
.then(async res => {
await User.updateOne({
_id: req.user._id
},{
$push: {
images: {
imgId: res.public_id,
imgVersion: res.version
}
}
})
})
.then(() => res.status(200).json({ msg: 'image uploaded. '}))
})
【问题讨论】:
标签: node.js cloudinary