【发布时间】:2011-07-18 15:09:50
【问题描述】:
我正在使用 Django/Python 构建一个网站,用户可以在其中上传一张照片,然后使用以下函数调整大小并保存:
from PIL import Image, ImageFile
def resize(file_to_resize, string_id,):
parser = ImageFile.Parser()
while True:
s = file_to_resize.read(1024)
if not s:
break
parser.feed(s)
image = parser.close()
ms = image.copy()
size = 320,240
ms.thumbnail(size, Image.ANTIALIAS)
ms.save('http://www.mysite.com/site_media/images/profile/' + string_id, "JPEG") `
这在本地运行时运行良好,但是一旦我将站点上传到我的主机并在 Apache 下运行它,我收到以下错误:
请求方法:POST
请求网址:http://www.mysite.com/saveimage/8/
Django 版本:1.2.1
异常类型:IOError
异常值:
[Errno 2] 没有这样的文件或目录:u'http://www.mysite.com/site_media/images/profile/8'
异常位置:/usr/local/lib/python2.6/site-packages/PIL/Image.py 保存,第 1299 行
Python 可执行文件:/usr/languages/python/2.6/bin/python
Python 版本:2.6.6
另外,我是 Web 开发和 Django/Python 的新手,这实际上是我正在学习的一个项目,并计划与朋友和家人分享,所以我不确定这是否是最好的方法当涉及到安全性并允许将文件直接写入站点时。任何建议表示赞赏。
【问题讨论】:
标签: python django python-imaging-library ioerror