RTC Forums
November 24, 2024, 05:57:53 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Download Binary File from a Web Server.  (Read 4399 times)
SteveG
RTC License++
*****
Posts: 17


« on: December 16, 2014, 02:27:09 AM »

Hi Danijel,

I have created a web server using a TRtcHTTPServer component and TRtcDataProvider components.

In a web browser, users are able to right click on a link and download a text file. This works fine.

The code I used is:

Code:
   

with Sender as TRtcDataServer do
   begin
      if Request.Complete then
      begin
         FConfigFile := CONFIG_FOLDER + CONFIG_FILENAME;

         if FileExists(FConfigFile) then
         begin
            Write(Read_File(FConfigFile));
         end;
      end;
   end;

I also want users to be able to download a binary file. I have tried a few different ways but the file doesn't download.

What is the correct method for downloading binary files?

Thanks.

= Steve
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: December 16, 2014, 05:13:01 AM »

The key to sending different content to the Web Browser is to set the correct Response Content Type header. If you do not set the Response Content Type header, Web Browser will assume that you are sending a HTML file. Different file types will require a different ContentType value to be handled properly by the Web Browser. For a working example on sending files of different types to Web Browsers, check the File_Server or the RTC_WebServer Demo, which use the File Provider implemented in the DataProviders\rtcFileProvider.pas unit.

Best Regards,
Danijel Tkalcec
Logged
SteveG
RTC License++
*****
Posts: 17


« Reply #2 on: December 16, 2014, 05:57:11 AM »

Ah, of course. Thanks Danijel! It was easier than I thought.

Regards,

Steve
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.