3

I created a simple DataSnap REST server in Delphi XE2 and i have a method which returns a TStream object to transfer a file. This works well but when i try to download a big file (~2,5GB) i got an

"out of memory"

error message on the server side.

I would like to download the file via internet browser (http://localhost:8080/datasnap/rest/TServerMethods1/GetFile).

Can rest service return big files?

I read this question and tryed that solution which works well when i use a small file.

Here is my simple code:

function TServerMethods1.GetFile: TStream;
var
  FileStream: TFileStream;
begin
  FileStream := TFileStream.Create('d:\file.exe', fmOpenRead);
  Result := FileStream;
end;

How can i download a big file from a REST server via internet browser?

Community
  • 1
  • 1
greenboy
  • 33
  • 5
  • Perhaps you may be able to let Indy serve the content in chunks. – Arnaud Bouchez May 04 '12 at 15:10
  • All decent HTTP server implementations transfer a response stream without loading it first into memory completely (AFAIK Indy does it right so no chunking is required). Looks like DataSnap REST services use a poor implementation. – mjn May 05 '12 at 11:39

1 Answers1

2

The result of your function is a TStream, try to increase the amount of memory for your application How can I enable my 32-bit Delphi application to use 4gb of memory on 64-bit windows (via Wow64.exe)?

Anyway, you are loading a very big amount of data. You should create a function which gives you the result in more small chunks.

Community
  • 1
  • 1
RBA
  • 12,337
  • 16
  • 79
  • 126
  • I created a function which gives the result in more small chunks but in this case (i think) i need to use a client application only (not the internet browser). – greenboy May 07 '12 at 06:15
  • I compiled my application into 64-bit platform and now it works. Thank you for your answer! – greenboy May 07 '12 at 06:23