Python & CGI. HELP please...

Jay Dorsey jay at jaydorsey.com
Thu Jun 5 07:54:26 EDT 2003


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