【问题标题】:Issues in saving resized file on S3在 S3 上保存调整大小的文件的问题
【发布时间】:2016-04-28 17:14:42
【问题描述】:

我在 S3 上使用 PIL 调整图像大小,但它给出的错误是

*** AttributeError: 'bytes' object has no attribute 'tell'

这是我的代码:

image = Image.open(self.file)
resized_image = image.resize((200,200), Image.ANTIALIAS)

 bucket = s3_connection()
 k = Key(bucket)
 filepath = '{0}/{1}'.format(filepath,filename) # filepath & filename values will be received 
 k.key = '{0}/{1}'.format('media', filepath) 
 k.set_contents_from_file(resized_image.tobytes()) <- This line is raising the above error.

【问题讨论】:

  • 你不应该在k.set_contents_from_file(file)这一行中使用self.file而不是file吗?
  • @MichielOvertoom 我刚刚从我的代码中复制了主要行,self.file 是原始的 imahe,而我必须保存调整大小的图像。我将编辑我的问题

标签: python amazon-s3 python-imaging-library


【解决方案1】:

需要使用set_contents_from_string()而不是set_contents_from_file()

更多详情请参考这个问题Upload resized image to S3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-05
    • 2012-10-19
    • 2011-09-03
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    相关资源
    最近更新 更多