我正在使用django-cumulus在Rackspace云上存储我的媒体。
我需要将数据从ImageField检索到PIL.Image。我需要它在这个图像上做一些改变(裁剪,滤镜等)。并将其保存到另一个积云ImageField。
我试过这段代码:
def field_to_image(field):
# field - cumulus-powered ImageField on some model
from StringIO import StringIO
from PIL import Image
r = field.read() # ERROR throws here!
image = Image.open(StringIO(r))
return image它在我一半的文件上运行良好,但在另一半文件上,我总是得到这样的错误:
Traceback (most recent call last):
File "tmp.py", line 78, in <module>
resize_photos(start)
File "tmp.py", line 59, in resize_photos
photo.make_thumbs()
File "/hosting/site/news/models.py", line 65, in make_thumbs
i = functions.field_to_image(self.img)
File "/hosting/site/functions.py", line 169, in field_to_image
r = field.read()
File "/usr/local/lib/python2.7/dist-packages/cumulus/storage.py", line 352, in read
if self._pos == self._get_size() or chunk_size == 0:
File "/usr/local/lib/python2.7/dist-packages/cumulus/storage.py", line 322, in _get_size
self._size = self._storage.size(self.name)
File "/usr/local/lib/python2.7/dist-packages/cumulus/storage.py", line 244, in size
return self._get_object(name).total_bytes
AttributeError: 'bool' object has no attribute 'total_bytes'有谁可以帮我?也许有更好的方法从rackspace中检索PIL.Image对象?
我正在尝试读取的文件()存在,并且可以通过Rackspace上的url获得
发布于 2014-06-06 20:18:30
如果在容器中找不到该文件,则返回False,因此这是一个非常令人困惑的错误。它现在已经在repo中修复了,但在发布版本中仍然没有修复:它返回None而不是False:https://github.com/django-cumulus/django-cumulus/blob/master/cumulus/storage.py#L203
但问题的根本原因是:找不到文件。
https://stackoverflow.com/questions/21085493
复制相似问题