Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs read file sent in the request without saving to file system

const multer = require('multer');
const {Duplex} = require('stream'); // It's a Native Node Module 
const fs = require('fs');
const readXlsxFile = require('read-excel-file/node')

const storage = multer.memoryStorage();
const upload = multer({
   storage: storage
});

function bufferToStream(bufferIn) {
    let duplex = new Duplex();
    duplex.push(bufferIn);
    duplex.push(null);
    return duplex;
}

app.post('/api/endpoint_name', upload.single('file'), function(req, res) {
    const file_buffer = req.file['buffer'];
    const file_stream = bufferToStream(file_buffer);
    const read_stream = fs.createReadStream(file_stream);
  	readXlsxFile(read_stream)
      .then(function(rows) {
      	console.log('Rows in the Excel : ', rows);
      });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: cant resolve module after typescript install 
Javascript :: add codegrepper 
Javascript :: p5 colored line 
Javascript :: ityped extension for react 
Javascript :: js object percorrer 
Javascript :: javascript unique id generator 
Javascript :: Add Navbar to React Redux CRUD App 
Javascript :: singly linked list create contains 3 nodes insert a node with data 50 
Javascript :: Pausing setInterval when page/ browser is out of focus 
Javascript :: Iterating over a TypedArray 
Javascript :: saving some fields of an instance in sequelize 
Javascript :: jquery select change price 
Javascript :: nvm install a particular version 
Javascript :: adding number in an array using the .forEach() method in javascript 
Javascript :: register js in viewyii2 
Javascript :: save canvas from console 
Javascript :: js invert array 
Javascript :: multi-line string shorthand javascript 
Javascript :: different way to for loop js 
Javascript :: clone copy a table in servicenow 
Javascript :: express static page 
Javascript :: vue get key inside component 
Javascript :: html how to remove class with js 
Javascript :: Bracket Spacing .prettierrc 
Javascript :: why typescript is superset of javascript 
Javascript :: Finding Attribute value with playwright in node.js 
Javascript :: typeorm sqlite Using Repositories 
Javascript :: Changing Async/Await to Promises.all to Speed Up API Calls in Node.JS 
Javascript :: multiplicar celulas js 
Javascript :: Custom usePagination hook example 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =