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
Updated the response code as I want to send a pdf file as attachment...
a!httpResponse( headers: { a!httpHeader( name: "Content-Type", value: "application/pdf" ), a!httpHeader( name: "Content-Disposition", value: "attachment; filename=filename.pdf" ) }, body: { todocument(121281) /*this is a pdf file from Appian*/ } )
Hi As of now, there are no such way to send a document to an external system through Web-API, but yes you can have a try on this. You can try the following approach for your R&D purpose, before we come to a conclusion: => Try to convert the document to Base64 format, and send this as an input to the External System using Web-API through POST call. => Once the content got Delivered to External Service, you need to again convert this Base64 to Document. Problem Statement in this approach: => Conversion of Document to Base64 in Appian => The External System must be capable of converting Base64 to Document again. Hope this information will help you.
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: {}
/*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)