【问题标题】:IOError: cannot identify image file -- works locally but not on HerokuIOError:无法识别图像文件——在本地工作,但在 Heroku 上不工作
【发布时间】:2013-08-15 18:36:59
【问题描述】:

我知道在 StackOverflow 上有无数关于这个错误的问题和答案,我已经全部阅读并尝试了他们的许多建议(Pillow 代替 PIL,io.BytesIO 代替 stringIO),但我仍然得到以下是同样的问题:

我正在编写代码来处理来自 S3 的图像——特别是将它们重新保存为 JPG,必要时旋转它们,并创建各种缩略图。代码的相关部分获取引用 S3 上图像的 URL 列表。我可以确认,是的,图像位于 URL 指定的位置的 S3 上。在每个 URL 上,我调用以下内容:

def process_new_image(file_url):        
    # Load the image and make it a PIL object
    try:
        fd = urllib.urlopen(file_url)
        image_file = io.BytesIO(fd.read())
        image = Image.open(image_file)
    except Exception, e:
        # ===> This is where the issue happens. <====
        raise

    # Read the exif data and potentially rotate the image
    transpose = Transpose()
    transposed_image = transpose.process(image)

    # Resave the image as a jpeg
    new_image_data = io.BytesIO()
    transposed_image.save(new_image_data, 'jpeg', quality=100)
    new_image_data.seek(0)

    try:
        self.image.save('image', ContentFile(new_image_data.read()), save=True)
    except Exception, e:         
        raise

    new_image_data.seek(0)
    self.process_thumbnails(new_image_data)

此代码在本地运行良好。但是当我在 Heroku 的暂存环境中运行它时,我得到“IOError:无法识别图像文件”。它在 JPG、PNG 和 GIF 上失败,它们都在本地工作。

关于我的环境的细节:

Django==1.5.1

枕头==2.1.0

pilkit==1.1.1

Python 2.7.3(两者上)

本地枕头编译:

--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** TIFF G3/G4 (experimental) support not available
--- FREETYPE2 support available
*** LITTLECMS support not available
*** WEBP support not available

在 Heroku Pillow 上编译:

       *** TKINTER support not available
       --- JPEG support available
       --- ZLIB (PNG/ZIP) support available
       --- TIFF G3/G4 (experimental) support available
       --- FREETYPE2 support available
       --- LITTLECMS support available
       *** WEBP support not available

【问题讨论】:

  • 嗯,这似乎与底层 S3 存储桶有关。如果图像是公开的,则代码有效。如果不是,那就不是。但我似乎无法让图像默认公开。我试过stackoverflow.com/questions/2547046/…,但没有用——只能手动将图像设置为公共作品,即obv。不是一个选项...
  • 是的,可以使用 k.set_acl('public-read') 以编程方式将文件设置为公开。

标签: django heroku python-imaging-library pillow


【解决方案1】:

与 S3 存储桶相关的问题。图像需要在存储桶中公开。应该关闭问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 2013-03-29
    • 2015-02-07
    相关资源
    最近更新 更多