首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cloudinary文件太大

cloudinary文件太大
EN

Stack Overflow用户
提问于 2020-09-30 19:19:26
回答 1查看 431关注 0票数 0

我使用cloudinary来上传和存储图片。当我尝试上传一个简单的JPG文件时,它给出了以下错误:

代码语言:javascript
复制
"PayloadTooLargeError: request entity too large"
 {
  message: 'request entity too large',
  expected: 1127957,
  length: 1127957,
  limit: 102400,
  type: 'entity.too.large'
}

以下是我的后端代码:

代码语言:javascript
复制
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. '}))
})
EN

回答 1

Stack Overflow用户

发布于 2020-09-30 20:34:39

看起来请求正文大于100MB,这是Cloudinary对上传请求的限制。任何大于此限制的请求都会收到您看到的错误。要上传大于100MB的文件,您必须以块的形式发送请求(参见文档here)。

您应该使用upload_large方法,而不是使用upload方法,因为它会自动拆分文件并将其分块上传。请参见- https://github.com/cloudinary/cloudinary_npm/blob/4b0bbccc9bc7c9340b59536e7c73e57c55da2e6f/lib/uploader.js#L54

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64136483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档