-
Notifications
You must be signed in to change notification settings - Fork 666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP stream #35
Comments
Hi, Thanks for trying out PptxGenJS and opening an issue. There's currently no functionality to create HTTP streams, but i am curious about a solution using streams. Is this for Node or web client, and how are the streams being used? |
Hi, Thanks for your quick answer. The streams are used to avoid creating the file in local, instead of that it goes within the response result from server to client and I finally downloaded in client side. (I haven't debugged how is that the pptx is generated and put into the response behind the scene, I guess it just keep it in memory as a buffer or blob). |
To save the powerpoint as an HTTP Stream instead of a file i've changed the function "doExportPresentation()" in the file pptxgen.js passing a callback that is called instead of "fs.writeFile" like this:
In an express application I write the content as a http stream like this:
when I want to save a file i pass a callback like this:
Maybe a better method is to use a flag that indicate that we want the data instead of saving the file, merging with the pull https://github.com/gitbrent/PptxGenJS/commit/b2cd8b0a91f233e17e831edd0a45c25fa0983b3a
and then when saving in nodejs in line 174:
|
Hi @GabrielM0 , Thanks for the feedback. I'm continuing to investigate methods to further utilize the callback just added in v1.2.0 I'll see what i can do to integrate your suggestions. |
+1 on this. I'm looking to use the pptxgenjs library in an AWS Lambda application that I will expose via the AWS API Gateway. I believe there is some functionality in Lambda for saving/retrieving files, but the "serverless" architecture really lends itself to grabbing stuff and just pushing it out via the HTTP stream rather than having to save it somewhere and then download it. |
Hi @necouchman , Thanks for the feedback. Now that PptxGenJS can utilize callbacks, can you enable streaming using a callback like the example above? (The function saveCallback(filename, data) {
// serve byte array as file attachment...
res.writeHead(200, { 'Content-disposition': 'attachment;filename='+filename, 'Content-Length': data.length });
res.end(new Buffer(data, 'binary'));
} |
@gitbrent, Also, when I look the "data" object via console.log inside the callback method, it comes back "undefined." I'm using pptxgenjs 1.4.0. |
@GabrielM0 Then, I can generate the http response in node: |
@FedeMM can you give me simple example of a officegen stream to front end , i created one but at front end it have been corrupted.... |
Hi @FedeMM , Thanks to @GabrielM0 and @kirkjensen18 and other posts here, i've got http streaming working now! The
pptx.save('http', steamCallback);
function steamCallback(data) {
var strFilename = "Node-Presenation-Streamed.pptx";
app.get('/', function(req, res) {
res.writeHead(200, { 'Content-disposition':'attachment;filename='+strFilename, 'Content-Length':data.length });
res.end(new Buffer(data, 'binary'));
});
app.listen(3000, function() {
console.log('PptxGenJS Node Demo app listening on port 3000!');
});
} |
Hi
I've been using officegen module for a while and there you can create a HTTP stream and send the pptx xml in the response by just doing pptx.generate ( response );
Is there any way to do this or similar with PptxGenJS?.
Thanks
The text was updated successfully, but these errors were encountered: