我正在尝试从存档中提取图像并在django模型中保存图像
with rarfile.RarFile(archive) as rf:
for name in rf.namelist():
image = rf.open(name)
fimg = FarcopImages.objects.create(scheme=image, article=article)
fimg.save()
错误:
'PipeReader' object has no attribute '_committed'
答案 0 :(得分:1)
您无法将RarFile
- esque文件实例保存到模型中。您需要使用内置的django File
对象。
https://docs.djangoproject.com/en/1.8/topics/files/#the-file-object
# Something like...
from django.core.files import File
# ...
with rf.open(name) as file_like_object:
FarcopImages.objects.create(scheme=File(file_like_object), article=article)