Datasnap rest server : problem with delphi 10.1

1

I then add the following code to display an image in a browser in my unit ServermethodUnit1 and my classe TserverMethods1

 

  TServerMethods1 = class(TDataModule)

  private

    { Déclarations privées }

  public

    { Déclarations publiques }

    function EchoString(Value: string): string;

    function ReverseString(Value: string): string;

    function getFile: TFileStream;

  end;

 

{$METHODINFO OFF}

function TServerMethods1.getFile: TFileStream;

begin

  GetInvocationMetadata.ResponseContentType := 'image/png';

  Result := TFileStream.Create('images\image.png', fmOpenRead or fmShareDenyNone);

end;

 

I start the datasnap server and i call in a browser this URl : http://localhost:61332/datasnap/rest/TServerMethods1/getFile/

The returned image is not correct : 

 

Executed: TServerMethods1.getFile

Result: {"result":[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,1,204,0,0,2,8,8,6,0,0,0,227,74,222,185,0,0,0,1,115,82,71,66,0,174,206

 

 

I compile the same project with Delphi 10 Seattle and Delphi XE4 and the browser displays the image correctly.

 

in Seattle 

 

Executed: TServerMethods1.getFile

Result: "�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0001�\u0000\u0000\u0002\b\b\u0006\u0000\u0000\u0000�J޹\u0000\u0000\u0000\u0001sRGB\u0000��\u001c�\u0000\u0000\u0000\u0004gAMA\u0000\u0000��\u000b�a\u0005\u0000\u0000\u0000\tpHYs\u0000\u0000\u000b\u0013\u0000\u0000\u000b\u0013\u0001\u0000��\u0018\u0000\u0000��IDATx^��\u0005�

What is wrong in delphi 10.1 ? is this a bug ? Is there a solution?

 

best regards 

 

Romuald Kler

 

 

 

 

 

Responses (4)
  • Accepted Answer

    Saturday, March 18 2017, 05:25 PM - #Permalink
    0

    Try this,

    at the end of the URL add ?json=false

    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, March 07 2017, 02:11 AM - #Permalink
    0

    Hi ,

    I do use 10.1 too and i am able to read images through Datasnap without any problem.

    Have you run seek(0,TSeekOrigin.soBeginning) before using the stream ?

    The reply is currently minimized Show
  • Accepted Answer

    Friday, January 27 2017, 07:01 AM - #Permalink
    1

    Hi,

    - I am not sure in your case, but I discovered, that new RAD studio don't support tga images, may be png too?

    Thanks.

     

    The reply is currently minimized Show
  • Accepted Answer

    Thursday, January 26 2017, 07:32 AM - #Permalink
    1

    Hi! Any solution to this??

    The reply is currently minimized Show
Your Reply

Please login to post a reply