I need to send AWS s3 file as email attachment in Base64 encoded. So reading and writing file content in streams, encoding each byte array in Base64.
The attachment is fine with text files but not getting decoded properly with pdf files.
Below is the sample code to write into outputStream. Reading file content in 3 bytes for proper Base64 encoding and decoding
byte[] bbuf = new byte[3];
while ((input = in.read(bbuf)) != -1)
{
// Url ByteArrayOutputstream
wr.write(Base64Encoder.encode(bbuf).getBytes());
wr.flush();
// Also writing to File locally to know received content
fs.write(bbuf, 0, input);
fs.flush();
}
I tried this solution which worked fine while writing to File but not with Base64 encoded email attachment.
I also tried encoding only 0-input byte array and writing those encoded bytes, which also failed.
Please help me,
Thanks