I have a templates files (.docx) in a Bucket S3. These files contains text and variables that will be replaced with some content. This replacement will be do with Docx4J. Once it is replaced, I have to upload these files to S3 again.
When I get the file from s3 I use:
byte[] doc = s3Client.downloadFile(s3TemplateFolder, "example-template-en.docx", bucket);
For replace the variables in the file I use Docx4J:
InputStream targetStream = ByteSource.wrap(doc).openStream();
HashMap mappings = new HashMap();
WordprocessingMLPackage wordMLPackage = Docx4J.load(targetStream);
VariablePrepare.prepare(wordMLPackage);
mappings.put("Download_date", "asd!");
wordMLPackage.getMainDocumentPart().variableReplace(mappings);
The problem is when I have to upload the updated file to s3 again. S3client only support File type. I don't know how should I do for convert WordprocessingMLPackage to a File again.
If you can think of another way to do this, you are welcome :)
Thank you so much.