简体   繁体   English

我在 mongodb 中上传图片时遇到错误无法读取未定义的属性“缓冲区”

[英]I got the error while uploading image in mongodb Cannot read property 'buffer' of undefined

When I upload the pdf using multer in mongodb in node.js then I got error "Cannot read property 'buffer' of undefined".I am trying to upload the pdf file in database.Please help to resolve this issue.Thanks in advance.当我在 node.js 中使用 mongodb 中的 multer 上传 pdf 时出现错误“无法读取未定义的属性‘缓冲区’”。我正在尝试上传数据库中的 pdf 文件。请帮助解决此问题。提前致谢。

const express=require('express');
const multer=require('multer');
const getstream = require('get-stream');
const resume=require('../model/Resume')

const router = new express.Router();
const uplaod = multer({

    limits:{
      fileSize: 100000
    },

    fileFilter(req,file,cb)
    {
      if(!file.originalname.endsWith('pdf'))
      {
        return cb(new Error('Upload the pdf file'))
      }

      cb(undefined,true);
    }
  });
router.post('/Resume',uplaod.single('avatar'),async (req,res)=>{


     req.resume.avatar=req.file.buffer
      await req.resume.save();
      res.send({sucess:'sucess'});
    },(error,req,res,next)=>{

      //It is used for print message otherwise it will give long html message

      res.status(404).send({error:error.message});
    })



  module.exports=router;

req.file does not exist, that's why you got this error req.file不存在,这就是你得到这个错误的原因

I think it should be req.files.file.buffer我觉得应该是req.files.file.buffer

if not, try to console.log(req) , and trace it to find the file如果不是,请尝试console.log(req) ,并跟踪它以找到该file

if there is no files or file in the req object, then the file hasn't been sent to the request如果req object 中没有filesfile ,则file尚未发送到request

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用 POSTMAN 在 mongodb 上上传图像,错误提示“无法读取未定义的属性‘缓冲区’” - I'm trying to upload an image on mongodb using POSTMAN the error says,“Cannot read property 'buffer' of undefined” 我收到此错误 => TypeError: Cannot read property 'image' of undefined - I got this error => TypeError: Cannot read property 'image' of undefined TypeError: Cannot read property 'then' of undefined -- 在使用 then 时出现此错误 - TypeError: Cannot read property 'then' of undefined --got this error while using then 我有这个错误: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'buffer' of undefined - I have this error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'buffer' of undefined 使用MongoDB时出现“无法读取未定义的属性'列表'” - I get a “Cannot read property 'list' of undefined” while using MongoDB MongoDB错误“无法读取未定义的属性” _id” - MongoDB Error 'Cannot read property '_id' of undefined' 在前端上传图片时无法读取未定义的属性“路径”(反应) - Cannot read property 'path' of undefined while uploading image upload on the frontend(react) 无法读取 Nodejs 上未定义错误的属性“图像” - Cannot read property 'Image' of undefined error on Nodejs nodejs并在上传文件时表达错误,“无法读取未定义的属性” - nodejs and express error when uploading file, "cannot read property of undefined" Node.js 出现错误无法读取未定义的属性“数据” - Node.js Got error cannot read property 'data' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM