簡體   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