LANSA Web API - sending files

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Joerg Hamacher
Posts: 120
Joined: Thu Feb 11, 2016 12:01 am

LANSA Web API - sending files

Post 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
Jurgen.Rentinck
Posts: 11
Joined: Wed Nov 25, 2015 9:02 pm
Location: Amsterdam
Contact:

Re: LANSA Web API - sending files

Post 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


Attachments
sendfileapi.zip
(8.98 KiB) Downloaded 1487 times
Post Reply