Solved

Show private files with a CGI application.

Posted on 2001-06-19
2
161 Views
Last Modified: 2010-04-04
I am looking for a solution to show files in private (not webserver public) directories on the web via a CGI executable. I tried it with a filestream it will work, but the browser can't recognize the filetype. For example:

c:\mywebserver\wwwroot is the location of my public files. I will give a user access to a file named: c:\test.pdf. The user have to call within it's browser my Delphi application getfile.exe:
http://mywebserver.com/cgi-bin/getfile.exe?file=c:\test.pdf&password=xxx
My application will load the file in a filestream and send the content of the filestream to the client. The data is OK. But IE don't understand that this is a pdf file and ask to download it and write it on disk with a strange name such as getfile.htm. If I choose to open it from the current location I will see the binary stream in my browser what I don't want.
0
Comment
Question by:snoei
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
TOndrej earned 75 total points
ID: 6207434
I think you should set the content type to 'application/pdf'. See TCGIResponse.ContentType property.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6207482
This should work when the client has Acrobat Reader installed:


var fs: TFileStream;
begin
  fs := TFileStream.Create('pdffile.pdf', fmOpenRead);
  try
    Response.ContentType := 'application/pdf';
    Response.ContentStream := fs;
    Response.SendResponse;
  finally
    fs.Free;
  end;
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question