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
LANSA Web API - sending files
-
Jurgen.Rentinck
- Posts: 11
- Joined: Wed Nov 25, 2015 9:02 pm
- Location: Amsterdam
- Contact:
Re: LANSA Web API - sending files
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.
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
- Attachments
-
- sendfileapi.zip
- (8.98 KiB) Downloaded 1487 times