Django引发错误:“ _ io.BytesIO”对象没有属性“名称”

时间:2018-06-23 18:14:38

标签: django

代码:

user_photo = UserPhoto.objects.get(user=request.user)

data = request.FILES['file_300']
input_file = BytesIO(data.read())
image_open = Image.open(input_file)
image_crop = image_open.crop((1, 1, 200, 200))

image_resize = image_crop.resize((300, 300), Image.ANTIALIAS)
image_file = BytesIO()
image_resize.save(image_file, 'JPEG')

data.file = image_file
user_photo.file_300 = data

user_photo.save()

跟踪:

Traceback (most recent call last): ... some lines removed ... File "D:\pythonDev\project\upward\chatkaboo\authapp\ajax_views.py", line 256, in upload_user_photo user_photo.save() ... some lines removed ... File "D:\pythonDev\interpreters\forMultichat\lib\site-packages\django\core\files\uploadedfile.py", line 67, in temporary_file_path return self.file.name AttributeError: '_io.BytesIO' object has no attribute 'name'

此代码是裁剪请求的图像文件并保存图像文件。

当文件为https://drive.google.com/open?id=1cc5_mOjqfOx6vvfR1yEEpxWH6YmdaX-m

时,此代码运行良好

但是当文件为https://drive.google.com/open?id=1pyeK9kcqQ_oOObX82gZCtC7HHng4YSNN

问题:

我该如何解决?我上面的两个图像文件之间有区别吗?

0 个答案:

没有答案