I’m receiving data sent by customer through mime message. The message contains XMLs and attachments(base64 encoded, currently testing with attachment size until 25 MB). I’m able to extract the content using mime services but how to base64 decode the extracted content of size this big? I tried converting into a string and decoded using the built in service but it is not working. Decoded contents need to be sent through FTP, irrespective of the size of the attachment, I see the size of the file as 1 KB in the ftp location post put operation. Whereas if I put the extracted content as is, then I can see the file same as the attachment received.
I did try that, faced the same issue. Is there any other of decoding which doesn’t involve conversion to string. I’m skeptical about this approach. I think there will be data loss.
I didn’t mention any encoding in these 2 services, left to Default. Is this might be the problem? What is the value to be given for Encoding filed while converting a base64 encoded mime stream?
The steps you mentioned will work for small files but if you are dealing with huge amounts of data then do not convert the stream to string in a Flow service. Map the stream directly to below service and that should give you the resulting decoded stream. Map the result from this service to the SFTP Put service in the WmPublic service for transmission.
I have not tested this code with large data but if you have issues, just tweak the byte allocation size.
IDataCursor pipelineCursor = pipeline.getCursor();
Object inStream = IDataUtil.get( pipelineCursor, "inStream" );
pipelineCursor.destroy();
try {
InputStream is = (InputStream) inStream;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int bytes;
byte[] data = new byte[1024];
while ((bytes= is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, bytes);
}
is.close();
InputStream resultStream = new ByteArrayInputStream(Base64.getDecoder().decode(buffer.toByteArray()));
IDataUtil.put( pipelineCursor, "resultStream", resultStream );
} catch (IOException e) {
IDataUtil.put( pipelineCursor, "errorMessage", e.toString() );
}
pipelineCursor.destroy();
I converted base64 encoded .7z attachment to byte array and transferred through FTP and checked. I’m able to read the file, unzip and see the contents. Thank you for your suggestions.