简体   繁体   中英

How to get xlsx sheet's data in body?

I have a function created in which I am trying to capture XLSX sheets data in it's body.

API -->

function uploadData(req, res, next) {
  console.log('req -->', req);
}

Route -->

router
  .route('/uploaddata')
  .post(uploadData)

I am trying to hit the API from postman and capture the data I am send as form-data file but unable to get the data.

earlier, I was capturing the data from local as let xlsFile = __dirname + '/assets/Test.xlsx'; so it went smooth but unable to send it through route.

Can anyone help me with the issue?

please add middleware for parsing like busyboy or multer.

const express = require('express');
const fileUpload = require('express-fileupload');


const app = express();

app.use(fileUpload({
  limits: { fileSize: 50 * 1024 * 1024 },
  useTempFiles : true,
  tempFileDir : '/tmp/'
}));

app.post('/upload', (req, res) => {
// req.files[forrmDataKey]
console.log(req.files.xlsfile);
  res.send({})
});


app.listen(8888, () => {
  console.log(`\nServer started on port 8888`);
});

You can use tmp path or you can get data from the request. Output:

  data: <Buffer >,
  size: 196608,
  encoding: '7bit',
  tempFilePath: '/tmp/tmp-1-1579799504065',
  truncated: false,
  mimetype: 'application/vnd.ms-excel',
  md5: '7fa977cc096355131625e1d6b21b4264',
  mv: [Function: mv] }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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