.
This commit is contained in:
+3
-3
@@ -25,11 +25,11 @@ def image_as_base64(image_file):
|
|||||||
# encoded_string = base64.b64encode(img_f.read())
|
# encoded_string = base64.b64encode(img_f.read())
|
||||||
encoded_string = base64.b64encode(image_file.file.read())
|
encoded_string = base64.b64encode(image_file.file.read())
|
||||||
mimetype, enc = mimetypes.guess_type(image_file.path)
|
mimetype, enc = mimetypes.guess_type(image_file.path)
|
||||||
|
# Treat unknown files as dicom
|
||||||
|
if None == mimetype:
|
||||||
|
return "data:application/dicom;base64,{}".format(encoded_string.decode("utf-8"))
|
||||||
if "dicom" in mimetype or "octet-stream" in mimetype:
|
if "dicom" in mimetype or "octet-stream" in mimetype:
|
||||||
return "data:{};base64,{}".format(mimetype, encoded_string.decode("utf-8"))
|
return "data:{};base64,{}".format(mimetype, encoded_string.decode("utf-8"))
|
||||||
# Treat unknown files as dicom
|
|
||||||
if None in mimetype:
|
|
||||||
return "data:application/dicom;base64,{}".format(encoded_string.decode("utf-8"))
|
|
||||||
return "data:image/{};base64,{}".format(mimetype, encoded_string.decode("utf-8"))
|
return "data:image/{};base64,{}".format(mimetype, encoded_string.decode("utf-8"))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user