繁体   English   中英

无法在 nodejs 和 firebase 函数中使用 busboy 处理 POST METHOD

[英]Not able to process POST METHOD using busboy in nodejs and firebase functions

您好我正在尝试将 post 方法与 busboy 一起用于多部分表单数据,即使代码在本地主机上测试它时工作得很好但是在 firebase function 上运行时我收到以下错误:

在 postman 中,我得到的响应是:错误:无法处理请求

如果您需要我提供更多信息,请告诉我。

Error: Unexpected end of form
    at Multipart._final (/workspace/node_modules/busboy/lib/types/multipart.js:588:17)
    at callFinal (node:internal/streams/writable:696:27)
    at prefinish (node:internal/streams/writable:725:7)
    at finishMaybe (node:internal/streams/writable:735:5)
    at Multipart.Writable.end (node:internal/streams/writable:633:5)
    at onend (node:internal/streams/readable:693:10)
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

如果有人可以帮我解决这个问题

下面是代码:

索引.js

var busboy = require('connect-busboy');

app.use(busboy());


app.use(cors()); 

const portCheck = process.env.PORT || 3001

app.use(express.json({limit: "50mb"}));
app.use(express.urlencoded({limit: "50mb", extended: true}));

app.use(cookieParser());
// app.use(express.static(path.join(__dirname, '../public-flutter')));
// app.get('/', (_, res) => {
//   res.sendFile(path.resolve(__dirname, '../public-flutter/index.html'));
// });

用户配置文件.js

router.post('/userprofile/check/busboy', async (req,res) => {
  console.log(req.body);
  
  const fields = {};
  req.busboy.on('field', (name, val) => {
    console.log('reached till here');
    
      console.log(`Processed field ${name}: ${val}.`);
    
    
    //fields.set(name,val)
    fields[name] = val;
    console.log(fields);
  });

  req.busboy.on('finish', function() {
    console.log('Done parsing form!');
    res.status(201).send();
  });
  
  req.pipe(req.busboy);
})
req.busboy.on('field', (name, val) => {
      
        fields[name] = val;
      
    });

    req.busboy.on('finish', () => {
              
                  try {
                    
                    notify = new userCampaign(fields);
                    notify.save((err,post) => {
                      if(err) {
                       console.log(err);
                      } 
                     
                      datacombine = new userCampaign(
                        {
                          title: post.title,
                          status: post.status,
                        }
                        )
                        datacombine.save((err,postcombine) => {
                          if(err) {
                            console.log(err);
                          }
                        res.status(201).send(postcombine);
                      })  

                     });
                  }
                  catch(e){
  
                  }
            })
            
            req.busboy.end(req.rawBody);
            req.pipe(req.busboy)
})

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM