Solved

Show private files with a CGI application.

Posted on 2001-06-19
2
152 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
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now