Sending documents to external system through a WebAPI call

Hello, Is it possible to send documents to an external system through a WebAPI call? I was playing with http response header 'Content-Disposition' with header value being ' attachment; filename=finename.pdf" '. But I don't get to understand how to embed a document from Appian 'content management system' either as a response header or body. When a call this API with this partial set up, the browser does at-least initiates a file download which I can't open(as I never really attached a file in response!). Is it even possible at all? Should the documents be attached in headers or body and how? Thanks for helping...

Here is the response I'm trying to prepare and see how I've embedded document object inside body. I'm sure this is not how it should be done, but I hope it will convey my intentions.

a!httpResponse(
headers: {
a!httpHeader(
name: "Content-Type",
value: "application/text"
),
a!httpHeader(
name: "Content-Disposition",
value: "attachment; filename=" & char(34) & local!username & ".txt" & char(34)
)
},
body: {
todocument(121330)
}
)

  Discussion posts and replies are publicly visible

Parents
  • with(

      local!pathArray: fn!cast('type!{www.appian.com/.../2009}Text, http!request.pathSegments),

      local!document: tointeger(index(local!pathArray, 1, null)),

      /* We don't want to serve arbitrary documents because it could be a security risk */

      local!extensionWhitelist: {"pdf", "txt", "png", "jpg", "jpeg"},

      if(

        /*The path must be only 1 value, the document ID, and that ID must be a number.Otherwise, we return a 404 Not Found*/

        or(

          length(local!pathArray) <> 1,

          isnull(local!document),

          not(contains(local!extensionWhitelist, document(local!document, "extension")))

        ),

        a!httpResponse(

          statusCode: 404,

          body: "404 Not Found",

          headers: {}

        ),

        a!httpResponse(

          /*If the query parameter "attachment" is set to true,set an HTTP header that tells the client that the body of the response should be downloaded. This overrides the default content-disposition of "inline; filename=<filename>.<extension>". We will automatically set the content-type and length.*/

          headers: if(

            http!request.queryParameters.attachment,

            a!httpHeader(

              name: "Content-Disposition",

              value: concat(

                "attachment; filename=""",

                document(local!document, "name"),

                ".",

                document(local!document, "extension"),

                """"

              )

            ),

            {}

          ),

          body: todocument(local!document)

        )

      )

    )

Reply
  • with(

      local!pathArray: fn!cast('type!{www.appian.com/.../2009}Text, http!request.pathSegments),

      local!document: tointeger(index(local!pathArray, 1, null)),

      /* We don't want to serve arbitrary documents because it could be a security risk */

      local!extensionWhitelist: {"pdf", "txt", "png", "jpg", "jpeg"},

      if(

        /*The path must be only 1 value, the document ID, and that ID must be a number.Otherwise, we return a 404 Not Found*/

        or(

          length(local!pathArray) <> 1,

          isnull(local!document),

          not(contains(local!extensionWhitelist, document(local!document, "extension")))

        ),

        a!httpResponse(

          statusCode: 404,

          body: "404 Not Found",

          headers: {}

        ),

        a!httpResponse(

          /*If the query parameter "attachment" is set to true,set an HTTP header that tells the client that the body of the response should be downloaded. This overrides the default content-disposition of "inline; filename=<filename>.<extension>". We will automatically set the content-type and length.*/

          headers: if(

            http!request.queryParameters.attachment,

            a!httpHeader(

              name: "Content-Disposition",

              value: concat(

                "attachment; filename=""",

                document(local!document, "name"),

                ".",

                document(local!document, "extension"),

                """"

              )

            ),

            {}

          ),

          body: todocument(local!document)

        )

      )

    )

Children
No Data