Basically is there a way to keep created file in variable so I can send it to API's such as google drive, etc. Similar to when I browse and select a file in browser, I can then keep the file in a variable, can something similar be done?
Hey @piyushmahensaria,
I'm making the assumption you are using node.js.
Here is some logic that should help you achieve what you're looking for:
workbook.xlsx.writeFile(filename);filename - we'll want to read the file contents somehow. fs.readFile(filename, function(err, data) { ... }); will get you your file contents.If you have more questions please ask.
Hey,
I think the case here was trying to avoid storing the file to disk and just directly streaming the created Exceljs workbook to some cloud storage API. For what it's worth, here's how you do it in Node with s3:
import * as exceljs from 'exceljs';
import * as aws from 'aws-sdk';
import * as Stream from 'stream';
const s3 = new aws.S3(/* put your s3 configuration here */);
const stream = new Stream.PassThrough();
const workbook = new exceljs.Workbook();
// Add images of cats to workbook
workbook.xlsx.write(stream)
.then(() => {
return s3.upload({
Key: PATH_IN_S3,
Bucket: BUCKET_NAME,
Body: stream,
ContentType: CONTENT_TYPE_EXCEL
}).promise();
})
.then(/* do whatever */)
.catch(/* handle error */);
@emraa your comment was super helpful to me. Thanks.
Most helpful comment
Hey,
I think the case here was trying to avoid storing the file to disk and just directly streaming the created Exceljs workbook to some cloud storage API. For what it's worth, here's how you do it in Node with s3: