Announcement

Collapse
No announcement yet.

Mirth HTTP Multipart File Name Attribute

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    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
    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.

    Comment


    • #3
      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?

      Comment


      • #4
        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.

        Comment


        • #5
          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 [email protected]

          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 [email protected] 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

          Comment


          • #6
            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

            Comment


            • #7
              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.

              Comment

              Working...
              X