I have a small python cgi script that accepts an image upload from the user, converts in into a different format, and saves the new file in a temp location. I would like it to then automatically prompt the user to download the converted file. I have tried:
# image conversion stuff....
print "Content-Type: image/eps\n" #have also tried application/postscript, and application/eps
print "Content-Disposition: attachment; filename=%s\n" % new_filename #have tried with and without this...
print open(converted_file_fullpath).read()
print
I have also tried:
print "Location: /path/to/tmp/location/%s" % new_filename
print
My browser either downloads script.cgi or script.cgi.ps. Any help is appreciated.
I’m not sure, but have you tried separating actual data from headers by newline? EDIT: writing
print "\n"outputs two newlines, so I think it should be written like that:Assuming that
new_filenamehas some reasonable value I can’t see what is wrong here.