Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 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.027 c
4-1103699867
leonidus
2004-12-22 10:17
2005.02.13
Как грамотно реализовать перетаскивание URL из IE в мою программу


14-1106479264
Чеширский_Кот
2005-01-23 14:21
2005.02.13
Нужна фотография Шевченки


4-1104229512
Shaman_RnD
2004-12-28 13:25
2005.02.13
CopyFileEx


1-1106306318
Weare
2005-01-21 14:18
2005.02.13
Почта и Делфи


1-1107143325
UVV
2005-01-31 06:48
2005.02.13
Чтение параметров из конфигурационного файла