web stats
Multipart payload resulted in Blank PDF and Corrupted Jpg - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-10-2019, 10:25 PM
jonats_rufo jonats_rufo is offline
What's HL7?
 
Join Date: Dec 2018
Posts: 2
jonats_rufo is on a distinguished road
Default Multipart payload resulted in Blank PDF and Corrupted Jpg

Hi,
Been struggling for 3 days on this issue
Sending a multipart payload in https to a system API, but when the system receives files in particular, the PDF file it received is empty on viewer and the JPEG is corrupted though the files received are on the same size in terms of bytes from the original file. The file that comes in are in BASE64 but I need to convert it to a binary in multipart before the API consumes it properly.


Been trying different charsets but to no success.
I tried SoapUI to feed the same files and copied the exact headers but Im getting success on SoapUI than in Mirth/Nextgen connect.

When I also save the decoded base64 using FileUtil, it is viewing OK in the local machine.

Below is the code:

channelMap.put('AttachmentFileName',msg['RequestPayload']['Attachment']['FileName'].toString());
channelMap.put('ContentType',msg['RequestPayload']['Attachment']['MimeType'].toString());
var base64Content = msg['RequestPayload']['Attachment']['Payload'].toString();
var DecodedDataContent =FileUtil.decode(base64Content);
var strDecodedDataContent = new java.lang.String(DecodedDataContent);

channelMap.put('BinaryDataBody', strDecodedDataContent);
channelMap.put('BoundaryUUID',UUIDGenerator.getUUI D());
FileUtil.write('C:\\Temp\\In\\'+connectorMessage.g etMessageId()+ '_'+msg['RequestPayload']['Attachment']['FileName'].toString(), true, DecodedDataContent);



[Separate Transformer]

var strHdr = "\r\n--" +$('BoundaryUUID') +"\r\n";
strHdr = strHdr + "Content-Type: "+ $('ContentType') +"; name=" +$('AttachmentFileName') +"\r\n";
strHdr = strHdr + "Content-Transfer-Encoding: binary\r\n";
strHdr = strHdr + 'Content-Disposition: form-data; name="file"; filename="' + $('AttachmentFileName') + '"\r\n';
strHdr = strHdr + "\r\n";
logger.info("MultiPart Header :" + strHdr);
strHdr = strHdr + $('BinaryDataBody') +"\r\n";
strHdr = strHdr + "--" + $('BoundaryUUID') + "--\r\n";
channelMap.put("PartContent",strHdr);
Reply With Quote
  #2  
Old 02-14-2019, 01:29 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 629
agermano is on a distinguished road
Default

Maybe this will help?

https://www.mirthcorp.com/community/...ight=multipart
Reply With Quote
  #3  
Old 02-14-2019, 08:56 PM
jonats_rufo jonats_rufo is offline
What's HL7?
 
Join Date: Dec 2018
Posts: 2
jonats_rufo is on a distinguished road
Default

Quote:
Originally Posted by agermano View Post

Thanks mate,, I've read that one before and it doesn't help either.
Tried examining the data sent by Mirth and I've started to point finger on this statement:

var strDecodedDataContent = new java.lang.String(DecodedDataContent)

I don't think this is the right java object to use and its default encoding(or probably not the right approach).
So i've also tried creating my own custom class(jar file) lib to decode the binary data using java String class but its the same outcome.. Empty PDF and broken JPG.. Im having JRE 1.8.0_152-b16..

Anyway, I gave up on this issue, I initiated plan B and just downloaded the 'Curl' tool and let it do the job on sending the multi-part attachment data to the Jira API.

cheers
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:36 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation