2022-09-08 18:57:53,375 [http-nio-8081-exec-9] ERROR c.b.t.w.e.RestResponseEntityExceptionHandler - 500 Status Code
c.a.SdkClientException: Unable to calculate MD5 hash: src/main/resources/maxmind/tech_fee_agreement.pdf (No such file or directory)
at c.a.s.s.AmazonS3Client.putObject(AmazonS3Client.java:1624)
at c.b.t.s.S3FileStorage.uploadPdfFile(S3FileStorage.java:100)
at c.b.t.s.S3FileStorage$$FastClassBySpringCGLIB$$7d744aa1.invoke(<generated>)
at o.s.c.p.MethodProxy.invoke(MethodProxy.java:218)
at o.s.a.f.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:685)
... 93 frames truncated
Caused by: j.i.FileNotFoundException: src/main/resources/maxmind/tech_fee_agreement.pdf (No such file or directory)
at j.i.FileInputStream.open0(FileInputStream.java)
at j.i.FileInputStream.open(FileInputStream.java:219)
at j.i.FileInputStream.<init>(FileInputStream.java:157)
at c.a.u.Md5Utils.computeMD5Hash(Md5Utils.java:97)
at c.a.u.Md5Utils.md5AsBase64(Md5Utils.java:104)
... 1 frames truncated
... 97 common frames omitted
I have created a method to generate a pdf file from an HTML template and save it locally and upload it to aws S3FileStorage then delete the local file. it is working fine in my local but why it is not able to Identify the path/ can't find the file or directory?
here is the method i created.
public void generatePdfFile(Map<String, Object> data, String pdfFileName) {
Context context = new Context();
context.setVariables(data);
String htmlContent = templateEngine.process("pdf/tech_fee_agreement.html", context);
try {
String fileNameWithPath = pdfDirectory + pdfFileName;
FileOutputStream fileOutputStream = new FileOutputStream(fileNameWithPath);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(htmlContent);
renderer.layout();
renderer.createPDF(fileOutputStream, false);
renderer.finishPDF();
} catch (FileNotFoundException | DocumentException e) {
logger.error(e.getMessage(), e);
}
}
the pdf directories strings are coming from the application.properties file -->
pdf.directory=src/main/resources/maxmind/
pdf.directory2=src/main/resources/maxmind/tech_fee_agreement.pdf