小编Qaz*_*zal的帖子

ValueError: Fileobj 必须实现读取

我正在使用 PIL 库将 gif 图像转换为 jpg 并将它们上传到 s3。我收到此错误:

ValueError: Fileobj 必须实现读取

这是读取图像并转换为jpg的代码的一部分:

im = Image.open(url)
i = 0
mypalette = im.getpalette()
try:
    while 1:
            im.putpalette(mypalette)
            new_im = Image.new("RGBA", im.size)
            new_im.paste(im)
            key = 'img'+str(i)+'.jpg'
            in_mem_file = io.BytesIO()
            new_im.save(in_mem_file, "JPEG")
            s3.upload_fileobj(in_mem_file.getvalue(), bucket, key)
            i += 1
            im.seek(im.tell() + 1)
except EOFError:
            pass
Run Code Online (Sandbox Code Playgroud)

我使用 io.BytesIO 来读取字节,但是我仍然遇到相同的错误。如果我从 in_mem_file 中删除 getvalue 空图像保存在存储桶中。

file-upload amazon-s3 iplimage

5
推荐指数
1
解决办法
4078
查看次数

标签 统计

amazon-s3 ×1

file-upload ×1

iplimage ×1