Python & CGI. HELP please...
Graeme Matthew
gsmatthew at ozemail.com.au
Thu Jun 5 08:23:46 EDT 2003
I scratching my head and thinking back to when I did this in perl, cant you
just:
print "Content-Type: application/pdf\n\n" #you need 2 returns here
#read file as binary and print to screen
#lets say read file into a variable called content
print content
> print "Content-Disposition: attachment; filename=%s\n" %
"Jay Dorsey" <jay at jaydorsey.com> wrote in message
news:mailman.1054814129.25949.python-list at python.org...
> On Thursday 05 June 2003 05:57, Enrico Morelli wrote:
>
> Have you tried opening the file up before you write the headers, so you
can
> obtain the length, then specifying a "Content-length: %d" % len(l) in the
> headers?
>
> Jay
>
> > I'm trying to write a script to be able to download/upload files
> > through web pages.
> > The upload script works fine but the download no.
> > When I download a file (pdf for example) using this script, I'm unable
> > to open it in local using acroread because at the end of the document I
> > found some html rows :-||
> > These rows are some html code inside of the script that I use to
> > display errors.
> >
> > Follow the method that I use to download files:
> >
> > def download(self, fullname, file):
> > print "Content-Type: application/download"
> > print "Content-Disposition: attachment; filename=%s\n" %
> > file try:
> > f=open(fullname, "rb")
> > l=f.read()
> > sys.stdout.write(l)
> > f.close()
> > sys.exit()
> > except:
> > msg="An error occurred during file transfer."
> > Display(msg, "")
> > sys.exit()
>
> --
> Jay Dorsey
> jay at jay dorsey dot com
>
>
More information about the Python-list
mailing list