Python & CGI. HELP please...
Enrico Morelli
enrico_morelli at yahoo.com
Thu Jun 5 10:37:18 EDT 2003
On Thu, 05 Jun 2003 07:54:26 -0400, Jay Dorsey wrote:
> 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
>
You are ready. I rewrite the method as follow and seems to be works:
Thanks a lot.
def download(self, fullname, file):
try:
f=open(fullname,"r").read()
print 'Content-type: application/octet-stream; name="%s"' % file
print 'Content-Disposition: inline; filename="%s"' % file
print 'Content-length: %s' % len(f)
print
sys.stdout.write(f)
except:
msg="An error occurred during file transfer."
Display(msg, "")
sys.exit()
>> 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()
More information about the Python-list
mailing list