Текущий архив: 2005.02.13;
Скачать: CL | DM;
Вниз
Отсылка файла с IdHttpServer Найти похожие ветки
← →
zdx 200 (2004-12-02 12:21) [0]Уважаемые Мастера! При отправке файла с помощью TIaHttpServer.ServeFile получается,
что IE сохраняет этот файл по имени ссылки, которой он запрашивается. Как передать реальное имя фала если оно отличается от имени ссылки
← →
Slym © (2004-12-03 04:44) [1]Замена ServeFile с поддержкой докачки! :)
unit ServFileEx;
interface
uses Windows,Classes,SysUtils,IdTCPServer,IdCustomHTTPServer;
procedure ServeFileEx(const FileName:string;AThread: TIdPeerThread;RequestInfo:TIdHTTPRequestInfo;ResponseInfo: TIdHTTPResponseInfo);
implementation
uses IdGlobal;
var IdMimeTable:TIdMimeTable=nil;
procedure ServeFileEx(const FileName:string;AThread: TIdPeerThread;RequestInfo:TIdHTTPRequestInfo;ResponseInfo: TIdHTTPResponseInfo);
var FileStream:TFileStream;
begin
try
FileStream:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyWrite);
try
try
FileStream.Position:=RequestInfo.ContentRangeStart;
except
on ERangeError do
begin
RequestInfo.ContentRangeStart:=FileStream.Position;
RequestInfo.ContentRangeEnd:=0;
end;
end;
if RequestInfo.ContentRangeEnd=0 then
RequestInfo.ContentRangeEnd:=FileStream.Size;
RequestInfo.ContentLength:=RequestInfo.ContentRangeEnd-RequestInfo.ContentRangeStart;
if FileStream.Size=RequestInfo.ContentLength then
ResponseInfo.ResponseNo:=200
else
ResponseInfo.ResponseNo:=206;
ResponseInfo.ContentType:=IdMimeTable.GetFileMIMEType(FileName);
ResponseInfo.ContentLength:=RequestInfo.ContentLength;
ResponseInfo.CustomHeaders.Clear;
ResponseInfo.CustomHeaders.Values["Accept-Ranges"]:="bytes";
ResponseInfo.CustomHeaders.Values["Content-Disposition"]:="filename=""+ExtractFileName(FileName)+""";
ResponseInfo.WriteHeader;
if not AnsiSameText(RequestInfo.Command,"HEAD") then
AThread.Connection.WriteStream(FileStream,false,false,ResponseInfo.ContentLength);
finally
FileStream.Free;
end;
except
on EFOpenError do Abort;
end;
end;
initialization
IdMimeTable:=TIdMimeTable.Create(true);
finalization
if assigned(IdMimeTable) then
FreeAndNil(IdMimeTable);
end.
← →
Slym © (2004-12-03 04:44) [2]Замена ServeFile с поддержкой докачки! :)
unit ServFileEx;
interface
uses Windows,Classes,SysUtils,IdTCPServer,IdCustomHTTPServer;
procedure ServeFileEx(const FileName:string;AThread: TIdPeerThread;RequestInfo:TIdHTTPRequestInfo;ResponseInfo: TIdHTTPResponseInfo);
implementation
uses IdGlobal;
var IdMimeTable:TIdMimeTable=nil;
procedure ServeFileEx(const FileName:string;AThread: TIdPeerThread;RequestInfo:TIdHTTPRequestInfo;ResponseInfo: TIdHTTPResponseInfo);
var FileStream:TFileStream;
begin
try
FileStream:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyWrite);
try
try
FileStream.Position:=RequestInfo.ContentRangeStart;
except
on ERangeError do
begin
RequestInfo.ContentRangeStart:=FileStream.Position;
RequestInfo.ContentRangeEnd:=0;
end;
end;
if RequestInfo.ContentRangeEnd=0 then
RequestInfo.ContentRangeEnd:=FileStream.Size;
RequestInfo.ContentLength:=RequestInfo.ContentRangeEnd-RequestInfo.ContentRangeStart;
if FileStream.Size=RequestInfo.ContentLength then
ResponseInfo.ResponseNo:=200
else
ResponseInfo.ResponseNo:=206;
ResponseInfo.ContentType:=IdMimeTable.GetFileMIMEType(FileName);
ResponseInfo.ContentLength:=RequestInfo.ContentLength;
ResponseInfo.CustomHeaders.Clear;
ResponseInfo.CustomHeaders.Values["Accept-Ranges"]:="bytes";
ResponseInfo.CustomHeaders.Values["Content-Disposition"]:="filename=""+ExtractFileName(FileName)+""";
ResponseInfo.WriteHeader;
if not AnsiSameText(RequestInfo.Command,"HEAD") then
AThread.Connection.WriteStream(FileStream,false,false,ResponseInfo.ContentLength);
finally
FileStream.Free;
end;
except
on EFOpenError do Abort;
end;
end;
initialization
IdMimeTable:=TIdMimeTable.Create(true);
finalization
if assigned(IdMimeTable) then
FreeAndNil(IdMimeTable);
end.
Страницы: 1 вся ветка
Текущий архив: 2005.02.13;
Скачать: CL | DM;
Память: 0.48 MB
Время: 0.038 c