生成后CGI下载镜像
我有一个小的 python cgi 脚本,它接受用户上传的图像,转换为不同的格式,并将新文件保存在临时位置。我希望它能够自动提示用户下载转换后的文件。我已经尝试过:
# 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
我也尝试过:
print "Location: /path/to/tmp/location/%s" % new_filename
print
我的浏览器下载 script.cgi
或 script.cgi.ps
。任何帮助表示赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定,但是您是否尝试过通过换行符将实际数据与标题分开?编辑:编写
print "\n"
输出两个换行符,所以我认为应该这样写:假设
new_filename
有一些合理的值,我看不到是什么这里错了。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_filename
has some reasonable value I can't see what is wrong here.事实证明,您可以使用
Location
标头来实现此目的,但它仅对我来说适用于绝对链接。所以,我知道,cgi 规范说相对链接应该适用于内部重定向,但这对我有用......
Turns out, you can use the
Location
header for this, but it only worked for me with an absolute link. So,I know, the cgi spec says that relative links should work for internal redirects, but this is what worked for me...