[Lazarus] watch window raise exception

Andrea Mauri andrea.mauri.75 at gmail.com
Fri Jun 11 10:05:14 CEST 2010


El jue, 10-06-2010 a las 17:23 -0300, Leonardo M. Ramé escribió:
> Hi, I'm trying to implement file downloading for an fpWeb CGI without
> success, I'm doing this so far:
> 
> procedure TFPWebModule1.TFPWebActions0Request(Sender: TObject;
>   ARequest: TRequest; AResponse: TResponse; var Handled: Boolean);
> var
>   lImage: string;
>   lFileStream: TFileStream;
> begin
>     lImage := '/home/leonardo/files/file1.dcm';
>     lFileStream := TFileStream.Create(lImage, fmShareDenyNone);
>     try
>       AResponse.ContentType := 'image/dicom3';
>       AResponse.CustomHeaders.Values['Content-Disposition'] :=
>         'attachment; filename=' + ExtractFileName(lImage);
>       AResponse.LoadFromStream(lFileStream, True);
>       AResponse.SendContent; // not sure if this is needed.
>     finally
>       lFileStream.Free;
>     end;
>   Handled := True;  
> end;
> 
> And the results of curl are this:
> 
> * About to connect() to localhost port 80 (#0)
> *   Trying ::1... connected
> * Connected to localhost (::1) port 80 (#0)
> > GET /cgi-bin/getstudy/StudyId?IdSeries=1 HTTP/1.1
> > User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7
> OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> > Host: localhost
> > Accept: */*
> > 
> < HTTP/1.1 200 OK
> < Date: Thu, 10 Jun 2010 20:17:52 GMT
> < Server: Apache/2.2.14 (Ubuntu)
> < Content-Disposition: attachment; filename=MR_4c1139a4b76d62c2.dcm
> < Content-Length: 0
> < Content-Type: image/dicom3
> < 
> * Connection #0 to host localhost left intact
> * Closing connection #0
> 
> As you can see, the Content-Lenght is 0, and the image isn't downloaded.
> What is the correct way of implementing this?.
> 

Sorry, I found the solution (I just needed to create an instance of
AResponse.ContentStream):

AResponse.ContentStream :=  TFileStream.Create(lImage, fmShareDenyNone);
try
  AResponse.ContentType := 'image/dicom3';
  AResponse.CustomHeaders.Values['Content-Disposition'] := 'attachment;
filename=' + ExtractFileName(lImage);
  AResponse.ContentLength := AResponse.ContentStream.Size;
  AResponse.SendContent;
finally
   AResponse.ContentStream.Free;
end; 

-- 
Leonardo M. Ramé
Griensu S.A. - Medical IT Córdoba
Tel.: 0351-4247979





More information about the Lazarus mailing list