代码:
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时
问题:
我该如何解决?我上面的两个图像文件之间有区别吗?