瀏覽代碼

[fix] detect image extension from content headers if extension isn't of image type

version-14
Anand Doshi 9 年之前
父節點
當前提交
138c7ad012
共有 1 個檔案被更改,包括 7 行新增0 行删除
  1. +7
    -0
      frappe/core/doctype/file/file.py

+ 7
- 0
frappe/core/doctype/file/file.py 查看文件

@@ -21,6 +21,7 @@ import os
import requests
import requests.exceptions
import StringIO
import mimetypes, imghdr

class FolderNotEmpty(frappe.ValidationError): pass

@@ -146,6 +147,12 @@ class File(NestedSet):

image = Image.open(StringIO.StringIO(r.content))
filename, extn = self.file_url.rsplit("/", 1)[1].rsplit(".", 1)

mimetype = mimetypes.guess_type(filename + "." + extn)[0]
if mimetype is None or not mimetype.startswith("image/"):
# detect file extension by reading image header properties
extn = imghdr.what(filename + "." + extn, h=r.content)

filename = "/files/" + strip(urllib.unquote(filename))

thumbnail = ImageOps.fit(


Loading…
取消
儲存