「Delphi2009でWebBrokerを使ってファイルをダウンロードさせるには」
回答
TFileStreamを使ってファイルを開き、
Response.ContentStreamを使います。
ヘッダーの処理(SetCustomHeader、Content-Type)がミソです。
ソース
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var fs:TFileStream;
begin
fs:=TFileStream.Create('c:\abcd.xls',fmOpenRead);
try
Response.ContentType:='application/vnd.ms-excel; name=abcd.xls';
Response.CustomHeaders.Clear;
//Response.SetCustomHeader('Server','www.hoge.hoge'); //適当に・・・
Response.SetCustomHeader('Content-Disposition','attachment; filename=abcd.xls');
Response.ContentStream:=fs;
Response.SendResponse;
finally
fs.Free;
end;
end;