web stats
Mirth HTTP Multipart File Name Attribute - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2013, 01:57 PM
Mireth Mireth is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 27
Mireth is on a distinguished road
Default Mirth HTTP Multipart File Name Attribute

I'm trying to send some data to a web service with Mirth using the multipart http sender. The problem is, the web service is expecting a specific value for the name attribute in the content-disposition field of the http message. Is there a parameter I can set in the outbound settings to change this value?

Currently Mirth is using the name of the temporary file it creates as both the 'name' and 'filename' attributes.

This is how it looks in the http message now (checked with wireshark)
Code:
        Content-Disposition: form-data; name="1f891c65-8837-4c32-a0d9-f72dc68c52216461482969038344197.tmp"; filename="1f891c65-8837-4c32-a0d9-f72dc68c52216461482969038344197.tmp"\r\n
I need the name attribute to just read 'file'.

Thanks!
Reply With Quote
  #2  
Old 08-06-2013, 07:59 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Unfortunately when Multipart is selected, the actual headers used within each part are generated internally and you don't have access to them. However you can get around it by faking your own multipart request:

Example - Custom Multipart HTTP Request
  • Destination Transformer
    • Mapper Step
      • Variable: boundary
      • Add to: Connector Map
      • Mapping: UUIDGenerator.getUUID()

  • Destination 1 - HTTP Sender
    • URL: http://requestb.in/1efjko41
    • Method: POST
    • Multipart: No
    • Headers
      • Content-Type: multipart/form-data; boundary=${boundary}; charset=UTF-8
    • Content:
      Code:
      --${boundary}\r\n
      Content-Disposition: form-data; name="file"\r\n
      Content-Type: text/plain; charset=UTF-8\r\n
      Content-Transfer-Encoding: binary\r\n
      \r\n
      ${message.encodedData}\r\n
      \r\n
      --${boundary}--

The reason why I inject Content-Type as a header rather than just using the "Content Type" field on the connector itself is because of a known issue: MIRTH-2832. That has already been fixed in 3.0, so it won't be an issue from there on.

I've attached the example channel as well (2.2.2).
Attached Files
File Type: xml Example - Custom Multipart HTTP Request.xml (6.9 KB, 172 views)
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 08-07-2013, 09:23 AM
Mireth Mireth is offline
OBX.1 Kenobi
 
Join Date: Aug 2010
Posts: 27
Mireth is on a distinguished road
Default Thanks!

That worked great, and now the behavior is accepted by the web server. One last thing, for some reason when the HTTP responses are being received, they are also being processed as messages even though the source is a channel reader.

This results in an endless stream of messages, of which only the first one contains relevant data we want stored.

Am I missing some reason for this behavior?
Reply With Quote
  #4  
Old 08-07-2013, 09:33 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Do you have Send Response To set to the same channel? Just switch that back to the default, which is "None".
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #5  
Old 11-14-2018, 01:43 AM
leon leon is offline
Mirth Newb
 
Join Date: Jul 2013
Location: South Africa
Posts: 7
leon is on a distinguished road
Default

Hi

I also need to upload a file to a (Redox) web service as multi-part form data where the form data name must be file.

I've read this thread and looked at the sample channel provided and modelled mine the same way, but I get an error if I send via Mirth vs using curl or postman. This is both for text and pdf files.

curl https://blob.redoxengine.com/upload \
-H "Authorization: Bearer <<ACCESS TOKEN>>" -X POST \
-F file=@test.txt

HTTP Response via curl:
{"URI": "https://blob.redoxengine.com/****"}

HTTP Response via Mirth:
Error saving file: No "file" key found in request body. Please contact Redox support at support@redoxengine.com for further investigation.

Mirth header:
Content-Type: multipart/form-data; boundary=${boundary}; charset=UTF-8
...

Mirth content in destination:
${boundary}
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain; charset=UTF-8
test
${boundary}

Contact me directly for the apiKey and secret values needed for authentication. It is set in the source transformer.

I know this uses an https URL, but when I proxy it through Apache (local http > Redox https) I still get the same result.

Also see
https://developer.redoxengine.com/da...through-redox/

I'm using Mirth 3.6.1

Thanks
Leon
Attached Files
File Type: xml TestFileUploadToRedox2.xml (16.4 KB, 12 views)
Reply With Quote
  #6  
Old 01-17-2020, 03:21 AM
droptix droptix is offline
What's HL7?
 
Join Date: Jan 2020
Posts: 4
droptix is on a distinguished road
Question

Quote:
Originally Posted by narupley View Post
Unfortunately when Multipart is selected, the actual headers used within each part are generated internally and you don't have access to them. However you can get around it by faking your own multipart request:

Example - Custom Multipart HTTP Request
  • Destination Transformer
    • Mapper Step
      • Variable: boundary
      • Add to: Connector Map
      • Mapping: UUIDGenerator.getUUID()

  • Destination 1 - HTTP Sender
    • URL: http://requestb.in/1efjko41
    • Method: POST
    • Multipart: No
    • Headers
      • Content-Type: multipart/form-data; boundary=${boundary}; charset=UTF-8
    • Content:
      Code:
      --${boundary}\r\n
      Content-Disposition: form-data; name="file"\r\n
      Content-Type: text/plain; charset=UTF-8\r\n
      Content-Transfer-Encoding: binary\r\n
      \r\n
      ${message.encodedData}\r\n
      \r\n
      --${boundary}--

The reason why I inject Content-Type as a header rather than just using the "Content Type" field on the connector itself is because of a known issue: MIRTH-2832. That has already been fixed in 3.0, so it won't be an issue from there on.

I've attached the example channel as well (2.2.2).
I just have the same challenge. But what is the content of the message? How do I need to convert a binary file? Can you give an example? Would help a lot
Reply With Quote
  #7  
Old 01-17-2020, 04:36 AM
droptix droptix is offline
What's HL7?
 
Join Date: Jan 2020
Posts: 4
droptix is on a distinguished road
Question

Quote:
Originally Posted by narupley View Post
[...] However you can get around it by faking your own multipart request:

Example - Custom Multipart HTTP Request
  • Destination Transformer
    • Mapper Step
      • Variable: boundary
      • Add to: Connector Map
      • Mapping: UUIDGenerator.getUUID()

  • Destination 1 - HTTP Sender
    • URL: http://requestb.in/1efjko41
    • Method: POST
    • Multipart: No
    • Headers
      • Content-Type: multipart/form-data; boundary=${boundary}; charset=UTF-8
    • Content:
      Code:
      --${boundary}\r\n
      Content-Disposition: form-data; name="file"\r\n
      Content-Type: text/plain; charset=UTF-8\r\n
      Content-Transfer-Encoding: binary\r\n
      \r\n
      ${message.encodedData}\r\n
      \r\n
      --${boundary}--
Great and thanks. I'm trying this but have one more question:

What is content of the message if I want to upload a binary file (JPG image)?

Do you have an example? Thanks.
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 03:57 AM.


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