2

i'm trying to use the mulesoft slack connector to upload a pdf file and a png file to a slack channel but i'm not able to configure the settings correctly to make this work. Has anyone been able to do so successfully? Here is my transform message just before the slack upload file connector:

%dw 2.0
output application/x-www-form-urlencoded
---
{
    "channels": "C03E4FWEQRY",
    "content": payload,
    "filename": "AdobePremierPro2021.pdf",
    "title": "AdobePremierPro2021",
    "filetype": "pdf"
}

It sends the file to the channel but all content is lost. The file comes across as a binary file that cannot be read.

Here is the XML snippet:

<flow name="upload-sub-flow" doc:id="1c8a2b29-5358-41bd-acd8-760676ddd86e" >
        <file:read doc:name="Read" doc:id="d4ba9476-4d83-47cd-8915-f1e8ef8e119e" config-ref="File_Config" path="/Users/aparkhe/AnypointStudio/1platform/slack-sys-api/src/main/resources/AdobePremierPro2021.pdf"/>
"]      <ee:transform doc:name="Transform Message" doc:id="72c36c3b-ce68-4c5d-8a0f-961f95a71569" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/x-www-form-urlencoded
---
{
    "channels": "C03E4FWEQRY",
    //"thread_ts": vars.SlackTS,
    "content":  payload,
    "filename": "AdobePremierPro2021.pdf",
    //"filename": "ArrivalPass.png",
    //"title": "AdobePremierPro2021",
    "filetype": "pdf"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>

        <slack:create-filesupload doc:name="Upload File" doc:id="08546a03-d746-42af-b50e-d45c11a5eb04" config-ref="Slack_Connector_Config"/>
    </flow>

Here is the POM dependency:

        <dependency>
            <groupId>com.mulesoft.connectors</groupId>
            <artifactId>mule4-slack-connector</artifactId>
            <version>1.0.12</version>
            <classifier>mule-plugin</classifier>
        </dependency>
  • I was actually looking at a different version of the slack connector. Therefore I got confused. Can you also add the connector dependency from POM just to be sure. Also it will make it easier for everyone. – Harshank Bansal May 23 '22 at 15:00
  • 1
    Just added the dependency to the post. – aditya parkhe May 23 '22 at 15:05
  • I tried it myself, but no luck. Tried to send both `multipart` and `www-urlencoded`. I will suggest to use either the [community version of slack](https://www.mulesoft.com/exchange/org.mule.connectors/mule-slack-connector/), or use HTTP request directly. I tried the community version and was able to send a PDF without any issue. – Harshank Bansal May 24 '22 at 08:10
  • I dont think i can use the community version but i can use http. Infact i tried using http and was not able to get it to work either. please let me know if you can get the http request to work. i would greatly appreciate it – aditya parkhe May 24 '22 at 13:57

1 Answers1

2

It seems like the slack connector is not enough matured yet, and is having problem with binary data. The file.upload endpoint of Slack supports two MIME types, application/x-www-form-urlencoded and other multipart/form-data. After checking the debug logs, it looks like the slack connector is only using the application/x-www-form-urlencoded encoding, which is not the best usecase for sending binary data.

I will recommend you to use either of these options:

  1. slack connector community version: It works great with similar configuration. You will not have to worry about the request structure as it will encapsulate everything. Also it uses multipart/form-data under the hood so you will not have any issues with PDF or PNG files. The usage is extremely simple so I will not add the details here. You will be able to understand it as soon as you drag the component.

  2. Use the traditional http:request connector. The tricky part here is to create the multipart/form-data payload. However you can use the Multipart dataweave module that will make it fairly simple. You will use Multipart::form function to create the form, and pass an array of the 4 fields, that you were setting in your transform message, using Multipart:field function.

    Your transform module will look like this

    %dw 2.0
    import dw::module::Multipart
    output multipart/form-data
    ---
    Multipart::form([
      Multipart::field("channels","#testing"),
      Multipart::field("filename","AdobePremierPro2021"),
      Multipart::field("filetype","pdf"),
      Multipart::field("file",payload, "application/pdf", "AdobePremierPro2021.pdf"),
    ])
    

    The payload here will be the output of the file:read operation

Harshank Bansal
  • 2,798
  • 2
  • 7
  • 22