Python 3.x S3文件只能以只读模式打开
我在django模型中有一个图像字段。 在保存表单中的图像之前,我想调整图像的大小并裁剪图像,然后只保存在s3 bucket中。当我使用django存储时,它工作得很好。移动到django-s3-storage,会给我一个错误 S3文件只能以只读模式打开 这是我在django表单中调整大小和编辑的代码片段:Python 3.x S3文件只能以只读模式打开,python-3.x,django,amazon-s3,django-models,boto3,Python 3.x,Django,Amazon S3,Django Models,Boto3,我在django模型中有一个图像字段。 在保存表单中的图像之前,我想调整图像的大小并裁剪图像,然后只保存在s3 bucket中。当我使用django存储时,它工作得很好。移动到django-s3-storage,会给我一个错误 S3文件只能以只读模式打开 这是我在django表单中调整大小和编辑的代码片段: def save(self): photo = super(ProfileUpdateForm, self).save() x = self.cleaned_
def save(self):
photo = super(ProfileUpdateForm, self).save()
x = self.cleaned_data.get('x')
y = self.cleaned_data.get('y')
w = self.cleaned_data.get('width')
h = self.cleaned_data.get('height')
image = Image.open(photo.image)
cropped_image = image.crop((x, y, w+x, h+y))
resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS)
fh = default_storage.open(photo.image.name, 'wb')
resized_image.save(fh, 'png')
fh.close()
return photo
另外,如果我删除open(fh=default_storage.open(photo.image.name))的模式arg,它不会编辑和裁剪图像,只会上载原始图像
此外,我尝试:打开PIL图像格式,但运气不佳:
fh = default_storage.open(resized_image, 'wb')
resized_image.save(fh, 'png')
fh.close()
最后,;我试图公开访问我的s3存储桶,并授予所有权限。也不管用。
我意识到一定是django-s3-storages。
我将是晚餐,并且非常高兴得到建议和/或任何帮助,因为我已经为此忙了两天多了