Doug,

It is probably a Windows/memory problem. You just can't make file streams that 
big. Your filestream code tries to swallow the entire PDF file whole into 
memory and *then* send it via HTTP to the client. If you try to read a file 
that is too large, your filestream read code will fail.

You probably should use a small (16-64K) buffer and "loop" through the PDF 
file, one buffer load at a time. Send the buffer to the client and repeat. A 
small buffer created as a local variable will work fine. Using a buffer lets 
you work on files of any size - multiple gigabytes, if necessary.

Remember that the last buffer load is probably only partially filled - you will 
have to count the number of actual bytes read into the buffer and make sure you 
only send that many to the client. Yeah, I know this is the old school way to 
do file transfers, but it actually works with (very) large files.

I have a similar problem with a ^...@#&! web browser unit/component I use to 
spider an SSL-secured web site and download files. The guy that wrote the 
component also used TFileStream, and it bombs on files larger than about 20MB - 
great planning in this day and age of large files. I have a bunch of 2-4 GB 
files to download, so the component is useless to me until I get around to 
rewriting the idiot thing. :-(

Don't be that guy ;-)

Best regards,

Kevin G. McCoy

--- In [email protected], Doug Hale <del...@...> wrote:
>
> I am using Delphi 7
> Window XP SP3
> Apache 2.2.14
> 
> I have an APACHE CGI module that I have developed. It transfers PDF 
> files to a request via HTTP.
> 
> the code:
> 
> procedure TWebModule1. GetDocument(Response: TWebResponse;Path, DocId : 
> String);
>   var
>      Filename : String;
>   ...
> 
>    begin
>    Filename := GetDocName(Path, DocId);
> 
>    ...
> 
>    Fs := TFileStream.Create(Filename, fmOpenRead, fmShareDenyNone);
>    Response.ContentType := 'application/pdf';
>    try
>      Response.ContentStream := Fs;
>      Response.SendResponse;
>    except
>      on E: Exception do
>        begin
>        Msg('EXCEPT %s %d', [E.Message, E.HelpContext]);
>        end;
>      end;
>   end;
> 
> The problem is that it won't correctly transfer files larger than around 
> 20Mbytes. Under that limit and everything is fine.
> 
> Is this a Windows problem.
> Is this an APACHE problem?  A CGI interface problem? A TResponse  
> problem? ??????
> I have been looking at this for a long time with no clue.
> 
> Any help at all would be greatly appreciated.
> 
> Doug
> P.S. The WebSite that uses it is http://www.doughale.info
>


Reply via email to