node.js - NodeJS 中的 cloudinary 文件上传遇到问题

标签 node.js mongodb express cloudinary

我正在尝试使用nodeJs在cloudinary上上传图像

这是我的代码

router.post('/imageUpload', upload.single('file'), function(req,res){

 User.findById(req.user._id,function(err,user){
   if (err) {
    console.log(err)
  } else {

    cloudinary.v2.uploader.upload(req.file.path,
     {public_id:user.username},
     function(result){
     console.log(result)
     });
    }
   })  
 });

我的问题是,我可以使用自定义名称在云文件中上传图像,但在控制台中它不会记录结果(即图像)对象

相反,它正在返回

undefined

最佳答案

您似乎正在尝试通过控制台记录错误,并且由于您已成功上传,因此其未定义。

尝试以下操作-

函数(错误,结果){console.log(错误,结果);

关于node.js - NodeJS 中的 cloudinary 文件上传遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48863437/

相关文章:

javascript - express js :separate controller and router file returns 404 error on route

mongodb - Mongoose 从数组中提取 ObjectId

java - 如何按内部数组大小对 MongoDB 查询结果进行排序?

express - 在 Express 中使用 supertest 时如何模拟 redis?

node.js - GET请求 'find by name'而不是通过id查找

javascript - node.js/ES6/类创建: SyntaxError: Unexpected reserved word

node.js - gulp - 排除文件不起作用

javascript - 坚持使用自定义过滤器获取实时数据的方法

node.js - npm - 设置项目特定的默认前缀/路径

javascript - 无法使用 moment.js 覆盖日期