node.js - Download xlsx from S3 and parse it -
i need service download excel file amazon s3, parse node-xlsx
the problem can't xlsx parse file. when try read file wrote, isn't found code.
i'm not quite sure if best approach, got far:
router.get('/process', (req, res) => { var filename = 'https://some-bucket.s3.amazonaws.com/some-excel-file.xlsx' https.get(filename, response => { var body = '' response.on('data', chunk => body += chunk) response.on('end', () => { //fs being imported on file fs.writefile(__dirname + '/test.xlsx', body) var f = fs.createreadstream(__dirname + '/test.xlsx') var book = xlsx.parse(f) book.foreach(sheet => console.log('sheet', sheet.name) ) res.status(200) }) .on('error', e => { res.status(500) }) }) return })
fs.writefile asynchronous. file won't there till call called.
https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback
fs.writefile('message.txt', 'hello node.js', (err) => { if (err) throw err; console.log('it\'s saved!'); });
Comments
Post a Comment