Layer7 API Management

Expand all | Collapse all

When building a multipart mime message with a binary attachments, how can you add such a binary attachment to the message?

  • 1.  When building a multipart mime message with a binary attachments, how can you add such a binary attachment to the message?

    Posted Apr 22, 2016 03:37 AM

    I am trying to build a multipart mime message with the gateway. When creating such a message i retrieve a binary attachment from a database (let's say an image). I add the retrieved blob to a context var (of type message) and subsequently add it to the builded message after a boundary.

    However when i add it to the message, it seems the gateway intereprets the message as text and the file is not readable anymore.

     

    My question is: how can i build a multipart mime message with a binary attachment (which i retrieve from a database) with the gateway?

     

    Many thanks,

     

    Jan Jaap Zoutendijk



  • 2.  Re: When building a multipart mime message with a binary attachments, how can you add such a binary attachment to the message?

    Broadcom Employee
    Posted Apr 28, 2016 09:06 PM

    Hi Jan,

    Should it be Base64 encoded first?

     

    Regards,

    Mark



  • 3.  Re: When building a multipart mime message with a binary attachments, how can you add such a binary attachment to the message?

    Posted Apr 29, 2016 05:05 AM

    Hi Mark,

     

    Thank you for your response. The file should not be base64 encoded first, i'm trying to send the original file.

     

    Regards,

     

    Jan Jaap



  • 4.  Re: When building a multipart mime message with a binary attachments, how can you add such a binary attachment to the message?
    Best Answer

    Broadcom Employee
    Posted May 26, 2016 02:23 AM

    Hello Jan,

    Here is a sample policy for multi-part response. But it's for text. I'm not sure if you can load binary data into a context variable ${attachment}, if yes, then you can use this policy.

     

    <?xml version="1.0" encoding="UTF-8"?>

    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">

        <wsp:All wsp:Usage="Required">

            <L7p:SetVariable>

                <L7p:AssertionComment assertionComment="included">

                    <L7p:Properties mapValue="included">

                        <L7p:entry>

                            <L7p:key stringValue="LEFT.COMMENT"/>

                            <L7p:value stringValue="v2 - 1"/>

                        </L7p:entry>

                    </L7p:Properties>

                </L7p:AssertionComment>

                <L7p:Base64Expression stringValue="VGhpcyBpcyBhbiBhdHRhY2htZW50Lg=="/>

                <L7p:VariableToSet stringValue="attachment"/>

            </L7p:SetVariable>

            <L7p:SetVariable>

                <L7p:AssertionComment assertionComment="included">

                    <L7p:Properties mapValue="included">

                        <L7p:entry>

                            <L7p:key stringValue="LEFT.COMMENT"/>

                            <L7p:value stringValue="v2 - 2"/>

                        </L7p:entry>

                    </L7p:Properties>

                </L7p:AssertionComment>

                <L7p:Base64Expression stringValue="LS1YWFhYYm91bmRhcnkNCkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbg0KDQp0aGlzIGlzIHRoZSBib2R5IHRleHQNCg0KLS1YWFhYYm91bmRhcnkNCkNvbnRlbnQtRGVzY3JpcHRpb246IEZpbGUgVHJhbnNmZXINCkNvbnRlbnQtRGlzcG9zaXRpb246IGF0dGFjaG1lbnQ7ZmlsZW5hbWU9InRlc3QudHh0Ig0KQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW0NCkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IGJpbmFyeQ0KRXhwaXJlczogMA0KQ2FjaGUtQ29udHJvbDogbXVzdC1yZXZhbGlkYXRlLCBwb3N0LWNoZWNrPTAsIHByZS1jaGVjaz0wDQpQcmFnbWE6IHB1YmxpYw0KDQoke2F0dGFjaG1lbnR9DQoNCi0tWFhYWGJvdW5kYXJ5LS0="/>

                <L7p:VariableToSet stringValue="resp"/>

            </L7p:SetVariable>

            <L7p:HardcodedResponse>

                <L7p:AssertionComment assertionComment="included">

                    <L7p:Properties mapValue="included">

                        <L7p:entry>

                            <L7p:key stringValue="LEFT.COMMENT"/>

                            <L7p:value stringValue="v2 -3"/>

                        </L7p:entry>

                    </L7p:Properties>

                </L7p:AssertionComment>

                <L7p:Base64ResponseBody stringValue="JHtyZXNwfQ=="/>

                <L7p:ResponseContentType stringValue="multipart/mixed;boundary=XXXXboundary"/>

            </L7p:HardcodedResponse>

        </wsp:All>

    </wsp:Policy>