[RESOLVED]Sending back binary file using fpweb cgi program. lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- BSaidus · 2024-03-15 09:50 Hello. How to send a binary file from fpweb CGI for download with a filename associated to this download ( not cgi script file name) I've tried like this : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   //  const CFile = 'abcd.bin'  ....   //     if ( LAction = 'ucp1' ) and ( LAction <> EmptyStr ) then    begin      if (SysUtils.FileExists(CFile)) then      begin        //AResponse.CustomHeaders.Add('Content-Description: File Transfer');      //AResponse.CustomHeaders.Add('Content-Type: application/octet- stream');        //AResponse.CustomHeaders.Add('Content-Disposition: attachment; filename=' + CFile);        //AResponse.CustomHeaders.Add('Content-Transfer-Encoding: binary');      //AResponse.CustomHeaders.Add('Expires: 0');        //AResponse.CustomHeaders.Add('Cache-Control: must-revalidate, post- check=0, pre-check=0');        //AResponse.CustomHeaders.Add('Pragma: public');        LStream := TMemoryStream.Create;        LStream.LoadFromFile(CFile);        try          //AResponse.Contents.Values['Content-Description'] := 'File Transfer';          AResponse.ContentType := 'application/octet- stream';          //AResponse.Contents.Values['Content-Disposition'] := 'attachment; filename=' + CFile;          //AResponse.Contents.Values['Content-Transfer-Encoding'] := 'binary';          //AResponse.Contents.Values['Content-Disposition'] := 'attachment; filename=' + CFile;          //AResponse.Contents.Values['Expires'] := '0';          //AResponse.Contents.Values['Cache-Control'] := 'must-revalidate, post-check=0, pre-check=0';          //AResponse.Contents.Values['Pragma'] := 'public';          //AResponse.ContentLocation := CFile;          AResponse.ContentStream := LStream;          //AResponse.CustomHeaders.Add('Content-Length:' + SysUtils.IntToStr(AResponse.ContentStream.Size));          AResponse.ContentLength := AResponse.ContentStream.Size;          //AResponse.SendHeaders();          AResponse.SendContent();        finally          LStream.Free;        end;        Exit;      end;    end;     the filename proposed in the save dialog is the name of the script. So how to modify this feature. In PHP using 'header' function it works. ---------------------------------------------------------------------- BSaidus · 2024-03-15 14:18 RESOLVED. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  class procedure tUcConfig.lfpProcessRequest(ARequest: Trequest; AResponse: TResponse);var  LStream: TMemoryStream;begin   if (SysUtils.FileExists(CFile)) then  begin    LStream := TMemoryStream.Create;    LStream.LoadFromFile(CFile);    AResponse.SetCustomHeader('Content-Description', 'File Transfer');    AResponse.SetCustomHeader('Content-Disposition', 'attachment; filename=' + AnsiDequotedStr(CFile, '"'));    try      AResponse.ContentType := 'application/octet-stream';      AResponse.ContentStream := LStream;      AResponse.ContentLength := AResponse.ContentStream.Size;      AResponse.SendContent();    finally      LStream.Free;    end;    Exit;   end; end;