#1 2014-06-03 00:08:32

moctes
Member
From: Mexico
Registered: 2013-05-11
Posts: 129

Returning file from interface based services

Hi,

I hope this one will be easier, I'm using interface based web services and I need to send a PDF file to the client ( testing with google chrome ) I have this code on place :

procedure GetReport( idReport:Integer );
var
  context: TServiceRunningContext;
begin
  context := CurrentServiceContext;

  context.Request.Call.OutHead   := HEADER_CONTENT_TYPE + HTTP_RESP_STATICFILE;
  context.Request.Call.OutBody   := './reports/January.pdf';
  context.Request.Call.OutStatus := 200;
end;

The former code is giving the following answer on the browser :

Server Error 404: Not Found

I don't know if this is the right way to serve files, because the procedure gets executed (already tried with function instead) but the file is not arriving to the browser, I looked at the sample 09 Http Api Web Server but the sample code isn't for interface based web services, may be it is not posible?

Offline

#2 2014-06-03 06:25:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,231
Website

Re: Returning file from interface based services

Ensure you get the latest 1.18 revision of the source and SAD PDF.
Then please read paragraph 17.7.4.2.3. Custom returned content

Offline

#3 2014-06-03 17:20:36

moctes
Member
From: Mexico
Registered: 2013-05-11
Posts: 129

Re: Returning file from interface based services

Thank you Arnaud,

If anybody ever needs to do this the working code is as follows :

function TServiceCustomers.GetReport(idReport: Integer): TServiceCustomAnswer;
var
  reportFileName: RawUTF8;
begin
  // some custom logic to locate the right file
  result.Header := HEADER_CONTENT_TYPE + HTTP_RESP_STATICFILE;
  result.Content:= reportFileName;
end;

Regards

Offline

Board footer

Powered by FluxBB