-
Notifications
You must be signed in to change notification settings - Fork 61
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
About generateData() function #11
Comments
If you created the ByteArrayOutputStream yourself, then instead of creating it, create a StreamTransferManager with numStreams = 1 and then:
If for some reason you have to use a ByteArrayOutputStream, e.g. because it's created by some code you don't control, then I don't suggest using this library at all, because it seems you can't avoid keeping all the data in memory anyway. |
Thanks, @alexmojaki for the quick reply. Lots of code... then -> Now here com.aspose.slides.Presentation. is class that save stream data in os |
@alexmojaki Any Luck!!! |
This has made me realise that requiring the user to call Then it's as I said, this code should work: OutputStream os = manager.getMultiPartOutputStreams().get(0);
presentation.save(os, SaveFormat.Pptx);
os.close(); |
It will definitely not write to disk at all. AWS should give you some metrics about RAM usage, try processing a big presentation and see what it says. If you don't change the default settings it should use very little memory and be able to process files up to 50GB. How big are these PowerPoint presentations? Are you sure you can't just hold the whole thing in memory and use the usual |
I just built only 30mb pptx file & got a matrix from AWS-Lambda, here:
It seems 1020mb are used only for building 30mb pptx file. And i'm not using String[] keys = input.get("keys"); // array of file[presentation file] keys stored on s3 bucket.
Presentation finalPresentation = new Presentation();
ISlideCollection finalPresentationSlides = finalPresentation.getSlides();
for (int i = 0; i < keys.length; i++) {
String key_name = keys[i];
S3ObjectInputStream s3is = null;
S3Object o = null;
try {
o = s3Client.getObject(bucket_name, key_name);
s3is = o.getObjectContent(); // converting file[presentation file] into byte form.
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
Presentation sourcePresentation = new Presentation(s3is);
ISlide slide = sourcePresentation.getSlides().get_Item(1); // getting second slide from prese...
finalPresentationSlides.addClone(slide); // attached into new presentation object.
try {
s3is.close(); // release object from RAM on each iteration
o.close(); // release object from RAM on each iteration
sourcePresentation.dispose(); // release object from RAM on each iteration
} catch (Exception e) {
e.printStackTrace();
}
} // end of loop.
final StreamTransferManager manager = new StreamTransferManager(bucket_name, "buildppt1.pptx", s3Client);
try {
MultiPartOutputStream os = manager.getMultiPartOutputStreams().get(0);
finalPresentation.save(os, SaveFormat.Pptx);
os.close();
} catch (Exception e) {
e.printStackTrace();
}
manager.complete(); |
I think this is the same issue as #2. The library isn't using the memory, it's just that a lot gets automatically preallocated by Java. I don't know if there's a way to configure that in Lambda but I don't think you need to (I don't think it charges RAM usage). Given that you have 3 GB available I still don't know why you anticipate running out unless you process some massive presentations. And even if you do, you somehow have to hold the |
Hi @alexmojaki Today, i was trying to build pptx file using 5 pptx file with size 298, 382, 170, 386, 276 MB but i'm getting an ERROR:
|
Did you upgrade to version 2.0.0? |
Yes. |
Here:
|
It looks like
The output was 21 (the number of output slides) and 132278973, the number of bytes being written all at once. The source presentation contained a video, a GIF, and some text, across 2 slides. So I'm sorry, but I don't see any way my library can help. You might have better luck writing to a file, but don't get too hopeful. You could also try contacting Aspose for help. I'm going to close this since I don't think it's a problem with this library, but feel free to comment if you still need help. |
Thanks, @alexmojaki. |
@alexmojaki it is not working. throwing an ERROR:
|
That indicates that something tried to write to the stream after closing it. I don't know how that happened, but your code at the end has some other problems that need fixing, and that might help. Use this code instead: os = manager.getMultiPartOutputStreams().get(0);
try {
finalPresentation.save(os, SaveFormat.Pptx);
os.close();
manager.complete();
} catch (Throwable e) {
manager.abort();
throw new RuntimeException(e); // or e.printStackTrace(); if you really want the code to continue
} In particular you need to abort if there's an exception, and not complete (your code was always completing). There's also no need to close if something goes wrong (i.e. in a |
I just recently got this lib. over the browser. As written in the README file, it is my solution. Thanks, @alexmojaki.
So just I use the sample code of StreamTransferManager with a little modify in stream generator for bigger data.
Now I'm troubled to implement this lib. with my requirement. Yeah!! it would be great if you help me. My whole explanation is here: -
Please guide me.
Thanks in advance.
The text was updated successfully, but these errors were encountered: