Page 1 of 1
LANSA Web API - sending files
Posted: Tue Aug 22, 2023 12:23 am
by Joerg Hamacher
Hi,
is it possible to send a complete file as response in a Web-API?
For example:
a request sends the name of a pdf document - can I send back the complete document in the API's response?
KInd regards,
Joerg
Re: LANSA Web API - sending files
Posted: Tue Aug 22, 2023 6:55 pm
by Jurgen.Rentinck
Hi Joerg,
This should be possible, you just need to make sure you set the contenttype correctly in the server routine to make sure the receiving site knows the type of content you return.
See the code below, I also added an export to make sure you have the complete schema definition.
Code: Select all
Begin_Com Role(*EXTENDS #PRIM_SRVM)
Srvroutine Name(Getfiles) Response(*HTTP #Context)
Define_Com Class(#Com_Home.Getfiles) Name(#Operation)
Define_Com Class(#prim_alph) Name(#filename)
If (#Operation.TryBind( #Context ))
#std_textl := #Operation.Request.filesID
#filename := ('c:\temp\&1').Substitute( #std_textl )
#Context.Response.HttpStatus := 200
#Context.Response.ContentType := 'application/pdf'
#Context.Response.SetContentFile FileName(#filename)
Endif
Endroutine
End_Com