<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2014-07-03 16:51 GMT-03:00 Leonardo M. Ramé <span dir="ltr"><<a href="mailto:l.rame@griensu.com" target="_blank">l.rame@griensu.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hi, I have a CGI program that serves some files using this code in an<br>
action:<br>
<br>
AResponse.ContentStream := TFileStream.Create(lImagePath, fmOpenRead);<br>
<br>
The problem I'm facing is that some times the client breaks the<br>
connection to the server, aparently leaving the file open. If the client<br>
tries to download the file again, a code 500 is returned.<br>
<br>
Is there a way to detect the connection break and destroy the stream<br>
gracefully?.<br></blockquote></div><div><br></div><div>You can use the FreeContentStream property and free your stream manually, e.g.:</div><div><br></div><div><div>var</div><div> f: TFileStream;</div><div>begin</div><div>
f := TFileStream.Create(...);</div><div> try</div><div> HttpResponse.FreeContentStream := False;</div><div> HttpResponse.ContentType := 'application/octet-stream';</div><div> HttpResponse.ContentStream := f;</div>
<div> HttpResponse.SendContent;</div><div> finally</div><div> f.Free;</div><div> end;</div><div>end;</div></div><div><br></div>-- <br>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>