SPUG: HTTP Headers
Parr, Ryan
Ryan.Parr at wwireless.com
Tue Dec 11 14:12:13 CST 2001
I like this solution very much. It works flawlessly. Thanks!
-- Ryan
-----Original Message-----
From: Trevor Leffler [mailto:tleffler at u.washington.edu]
Sent: Tuesday, December 11, 2001 10:35 AM
To: spug-list at pm.org
Subject: Re: SPUG: HTTP Headers
Ryan,
First off, I'm going to ignore that you're storing entire binary docs in
your DB, rather than letting your web server serve them up via the
filesystem. Anywho...
We came up with one possible solution, which assumes you're using
Apache. Create a link URL such as:
/download/CMS_SOP.doc?docid=334
Since the real filename is in the URL, your browser will use it in the
"Save" dialog box.
The /download directory has only a .htaccess file with these contents:
ErrorDocument 404 /somepath/nph-download.cgi
Since /download/CMS_SOP.doc doesn't actually exist, the nph-download.cgi
script gets called instead. That script then finds the document via
your DB thanks to the docid you passed it (we just store the private
path to the doc, rather than the doc itself), prints the appropriate
HTTP headers and Content-type, and streams the file contents to the browser.
The reason you use an nph- script is to override the server headers,
which will show a 404 "File not found" status. You'll want to start by
printing something like:
print "HTTP/1.1 200 OK\n",
"Server: $ENV{SERVER_SOFTWARE}\n";
Then print an error page is something fails, or your Content-type and
contents if everything succeeds.
As an aside, you might think about using adequately random docid's, or
perhaps encrypting them so that I can't download all your documents via
iteration. That is, if doc access is an issue.
Have fun!
--
Trevor Leffler, Software Developer
PETTT / Ed-Tech Development Group
University of Washington
(206) 616-3406 / OUGL 230, Box 353080
Parr, Ryan wrote:
> I'm currently moving the intranet site I work on to be completely database
> based. However, I'm running into a snag with delivering documents to the
> user. Rather, delivering documents other than HTML to the user.
>
> If I have my CGI load a word doc that's stored in the database, and send
it
> to the user with the appropriate mime type, the browser can handle it
> appropriately. Unfortunately though, I have no way to specify a filename
for
> the content. So instead of receiving an Open/Save dialog for CMS_SOP.doc
> they receive an Open/Save dialog for /cgi-bin/loadpage.cgi?id=334, or the
> browser loads the word doc with the filename /cgi-bin/loadpage.cgi?id=334.
>
> I haven't been able to find any standard HTTP headers that deal with this
> scenario, nor any IE specific extension headers. I'm in a controlled
> environment so everyone has IE 4+. This approach to document delivery
seems
> natural enough to me that I'm sure a thousand developers before me have
> attempted it, certainly some with success. Have any of you?
>
> -- Ryan Parr
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
More information about the spug-list
mailing list