我正在 Pylons 中创建一个网络应用程序,并且正在处理图像上传操作。这目前在我的 Windows 机器上使用 egg:paste#http 运行,在 pylons 文档快速入门中描述的基本开发配置中。
当我将图像发布到我的应用程序,然后将图像移动到 Web 根目录,然后在浏览器中拉出上传的图像时,图像出现失真。这是我上传 Yahoo! 的 GIF 时得到的。徽标,但大多数文件根本没有显示在浏览器中,可能是因为损坏:
扭曲的雅虎徽标 http://www.freeimagehosting.net/uploads/d2c92aef00.png
这是我正在使用的基本代码(直接来自 pylons 文档):
os_path = os.path.join(config.images_dir, request.POST['image'].filename)
save_file = open(os_path, 'w')
shutil.copyfileobj(request.POST['image'].file, save_file)
request.POST['image'].file.close()
save_file.close()
request.POST['image'] 是一个 cgi.FieldStorage 对象。我认为这可能是 Windows 行结尾的问题,但我不确定如何检查或纠正它。是什么导致我上传的图像失真/损坏?