我正在使用 django-ckeditor。
我正在以图像和 Flash 上传图标上传图像文件和 .swf 文件。但是当我上传除这些文件之外的文件时,我收到错误为“无法识别图像文件”。对于 swf 文件,不会创建缩略图,并且会显示没有任何 url 的虚拟图像。
我在 ckeditor 中的观点为:@csrf_exempt
def upload(request):
upload = request.FILES['upload']
upload_ext = os.path.splitext(upload.name)[1]
upload_filename = get_upload_filename(upload.name, request.user)
out = open(upload_filename, 'wb+')
for chunk in upload.chunks():
out.write(chunk)
out.close()
if upload_ext != ".swf":
create_thumbnail(upload_filename)
url = get_media_url(upload_filename)
url = url.replace("\\", "/")
return HttpResponse("""
<script type='text/javascript'>
window.parent.CKEDITOR.tools.callFunction(%s, '%s');
</script>""" % (request.GET['CKEditorFuncNum'], url))
缩略图,
def create_thumbnail(filename):
image = Image.open(filename)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
imagefit = ImageOps.fit(image, THUMBNAIL_SIZE, Image.ANTIALIAS)
imagefit.save(get_thumb_filename(filename))
任何人都可以帮我解决这个问题..