Datasnap rest server : problem with delphi 10.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)


    { Déclarations privées }


    { Déclarations publiques }

    function EchoString(Value: string): string;

    function ReverseString(Value: string): string;

    function getFile: TFileStream;




function TServerMethods1.getFile: TFileStream;


  GetInvocationMetadata.ResponseContentType := 'image/png';

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



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 (5)
  • Accepted Answer

    Monday, June 19 2017, 01:08 PM - #Permalink


    I have the same problem, however with sending txt file. In delphi XE5, sending the file is done normally. In delphi xe10.2, the file comes in JSON format and with the characters all in byte format.

    The scenario is as follows: I have a datasnap server and its consumption is done in android, programming by eclyse.

    Any suggestions to correct?


    (Translated from Portuguese by google translator)


    Att, Juliano

    The reply is currently minimized Show
  • Accepted Answer

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

    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

    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


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



    The reply is currently minimized Show
  • Accepted Answer

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

    Hi! Any solution to this??

    The reply is currently minimized Show
Your Reply

Please login to post a reply.........