我开发了aws-lambda函数,该函数从s3存储桶收集pptx文件源,并从给定的源构建新的演示文稿。 但是,如果sourec文件的大小很大,那么我会报错:
{
"errorMessage": "Java heap space",
"errorType": "java.lang.OutOfMemoryError",
"stackTrace": [
"com.aspose.slides.internal.e5.void.setCapacity(Unknown Source)",
"com.aspose.slides.internal.e5.void.b(Unknown Source)",
"com.aspose.slides.internal.e5.void.write(Unknown Source)",
"com.aspose.slides.internal.eu.case.write(Unknown Source)",
"com.aspose.slides.internal.eu.case.write(Unknown Source)",
"com.aspose.slides.internal.eu.boolean.write(Unknown Source)",
"com.aspose.slides.internal.eu.goto.write(Unknown Source)",
"com.aspose.slides.internal.eu.public.byte(Unknown Source)",
"com.aspose.slides.internal.eu.public.case(Unknown Source)",
"com.aspose.slides.internal.eu.public.int(Unknown Source)",
"com.aspose.slides.internal.eu.switch.public(Unknown Source)",
"com.aspose.slides.internal.eu.switch.if(Unknown Source)",
"com.aspose.slides.acy.do(Unknown Source)",
"com.aspose.slides.Presentation.do(Unknown Source)",
"com.aspose.slides.Presentation.do(Unknown Source)",
"com.aspose.slides.Presentation.do(Unknown Source)",
"com.aspose.slides.Presentation.save(Unknown Source)",
"com.prdxn.testing.demo.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:60)",
"com.prdxn.testing.demo.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:1)"
]
}
public class LambdaFunctionHandler implements RequestHandler<Map<String, String[]>, String> {
@Override
public String handleRequest(Map<String, String[]> input, Context context) {
// AWS S3 bucket configuration..
String AccessKeyID = "xxx";
String SecretAccessKey = "xxx";
String clientRegion = "xxx";
String bucket_name = "xxx";
BasicAWSCredentials creds = new BasicAWSCredentials(AccessKeyID, SecretAccessKey);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion)
.withCredentials(new AWSStaticCredentialsProvider(creds)).build();
// Closing AWS S3 bucket configuration..
Presentation finalPresentation = new Presentation();
ISlideCollection finalPresentationSlides = finalPresentation.getSlides();
String dest = "result.pptx";
String[] keys = input.get("keys"); // get pptx file name from s3 bucket
for (int i = 0; i < keys.length; i++) {
String key_name = keys[i];
Presentation sourcePresentation = new Presentation(
s3Client.getObject(bucket_name, key_name).getObjectContent());
try {
finalPresentationSlides.addClone(sourcePresentation.getSlides().get_Item(0));
} catch (Exception e) {
e.printStackTrace();
} finally {
sourcePresentation.dispose();
}
}
final StreamTransferManager manager = new StreamTransferManager(bucket_name, dest, s3Client);
MultiPartOutputStream os = null;
try {
os = manager.getMultiPartOutputStreams().get(0);
finalPresentation.save(os, SaveFormat.Pptx);
} catch (Exception e) {
e.printStackTrace();
} finally {
os.close();
}
manager.complete();
// Finishing of
return "success";
}
}