生成后CGI下载镜像

发布于 2024-09-09 00:51:29 字数 579 浏览 0 评论 0原文

我有一个小的 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.cgiscript.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-09-16 00:51:29

我不确定,但是您是否尝试过通过换行符将实际数据与标题分开?编辑:编写 print "\n" 输出两个换行符,所以我认为应该这样写:

print "Content-Type: image/eps"
print "Content-Disposition: attachment; filename=%s" % new_filename
print
print open(converted_file_fullpath).read()

假设 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:

print "Content-Type: image/eps"
print "Content-Disposition: attachment; filename=%s" % new_filename
print
print open(converted_file_fullpath).read()

Assuming that new_filename has some reasonable value I can't see what is wrong here.

翻身的咸鱼 2024-09-16 00:51:29

事实证明,您可以使用 Location 标头来实现此目的,但它仅对我来说适用于绝对链接。所以,

print 'Location: http://example.com/path/to/tmp/location/%s' % new_filename
print

我知道,cgi 规范说相对链接应该适用于内部重定向,但这对我有用......

Turns out, you can use the Location header for this, but it only worked for me with an absolute link. So,

print 'Location: http://example.com/path/to/tmp/location/%s' % new_filename
print

I know, the cgi spec says that relative links should work for internal redirects, but this is what worked for me...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文