How can I stream large files directly to my web server's hard drive?
I'd like to upload files to a simple web server based on the
TIdHTTPServer component (Indy 10, Delphi 7). I'm new to this, but I
manged to produce a piece of code that does what I want:
procedure TForm1.HTTPServerCreatePostStream(AContext: TIdContext;
var VPostStream: TStream);
begin
VPostStream :=TMemoryStream.Create;
end;
procedure TForm1.HTTPServerCommandGet(AContext: TIdContext;
begin
...save ARequestInfo.PostStream to a file...
end;
The problem is that I would like this to work with very large files
(several gigagbytes) and my idea was to save the POST-data directly to
a TFileStream instead so that the data doesn't consume all my RAM.
procedure TForm1.HTTPServerCreatePostStream(AContext: TIdContext;
var VPostStream: TStream);
begin
VPostStream :=TFileStream.Create(GetTempFilename(), fmCreate);
end;
procedure TForm1.HTTPServerCommandGet(AContext: TIdContext;
begin
...rename the temporary filename to the actual filename....
end;
When executing this code, the file gets uploaded like it should and my
program only uses a couple of megabytes of RAM, but when the file
upload is completed, the program suddenly reads the whole file in to
memory and I get an EOutOfMemory exception :(
So, how can I stream large files directly to my web server's hard
drive?
Thanks,
Filip Lundeholm