我正在使用 PIL 使用此方法调整上传文件的大小:
def resize_uploaded_image(buf):
imagefile = StringIO.StringIO(buf.read())
imageImage = Image.open(imagefile)
(width, height) = imageImage.size
(width, height) = scale_dimensions(width, height, longest_side=240)
resizedImage = imageImage.resize((width, height))
return resizedImage
然后我使用此方法在我的主视图方法中获取 resizedImage :
image = request.FILES['avatar']
resizedImage = resize_uploaded_image(image)
content = django.core.files.File(resizedImage)
acc = Account.objects.get(account=request.user)
acc.avatar.save(image.name, content)
但是,这给了我“读取”错误。
痕迹:
异常类型:/myapp/editAvatar 处的 AttributeError 异常值:读取
知道如何解决这个问题吗?我已经玩了好几个小时了!谢谢!
尼库尼