Search code examples
delphidatasnap

Content-Type response in the REST DataSnap not working for me


I build a DataSnap REST server with the wizard in Embarcadero® Delphi 10.4 Architect. I need to create a simple method to get a PDF file from a client, such as Postman.

I wrote the next code after reading Return an image from a Delphi REST server and show it in a browser:

function TServerMethods1.GetPdf: TFileStream;
var
 fStream: TFileStream;
begin
 fStream := TFileStream.Create('images/ticket.pdf', fmOpenread or fmShareDenyNone);
 GetInvocationMetadata.ResponseContentType := 'application/pdf';
 Result := fStream;
end;

In the AfterDispatch event:

procedure TWebModule1.WebModuleAfterDispatch(Sender: TObject; Request: TWebRequest;
  Response: TWebResponse; var Handled: Boolean);
begin
  Response.ContentType := 'application/pdf';
end;

But when I call the method from postman, I get an error because the result is a JSON file, not a PDF:

{"result":[[37,80,68,70,45,49,46,55,10,37,226,2...]]}

The Content-Type value is OK.

postam header results

What is wrong in my code?


Solution

  • As Oliver said in the comments, just add the parameter ?json=false to the URL

    Postman

    It work!!!