生成后的CGI下载图像 [英] CGI download image after generating
问题描述
我有一个小的python cgi脚本,它接受用户上传的图像,转换成其他格式,然后将新文件保存在临时位置。然后,我希望它自动提示用户下载转换后的文件。我尝试过:
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
我也尝试过: / p>
I have also tried:
print "Location: /path/to/tmp/location/%s" % new_filename
print
我的浏览器下载 script.cgi
或 script.cgi.ps
。感谢您的帮助。
My browser either downloads script.cgi
or script.cgi.ps
. Any help is appreciated.
推荐答案
我不确定,但是您是否尝试过用换行符将实际数据与标头分开?编辑:编写 print \n
输出两个换行符,所以我认为应该这样写:
I'm not sure, but have you tried separating actual data from headers by newline? writing print "\n"
outputs two newlines, so I think it should be written like that:
print "Content-Type: image/eps"
print "Content-Disposition: attachment; filename=%s" % new_filename
print
print open(converted_file_fullpath).read()
假定 new_filename
具有合理的价值,我看不到这里出了什么问题。
Assuming that new_filename
has some reasonable value I can't see what is wrong here.
这篇关于生成后的CGI下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!