mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-01 05:49:58 +00:00
Fix #1859 (Upload of jpg files without installed imagemagick doesn't work)
This commit is contained in:
parent
3c1b06872d
commit
bbf609b880
@ -32,7 +32,7 @@ from tempfile import gettempdir
|
|||||||
import requests
|
import requests
|
||||||
from babel.dates import format_datetime
|
from babel.dates import format_datetime
|
||||||
from babel.units import format_unit
|
from babel.units import format_unit
|
||||||
from flask import send_from_directory, make_response, redirect, abort, url_for, request
|
from flask import send_from_directory, make_response, redirect, abort, url_for
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from sqlalchemy.sql.expression import true, false, and_, text
|
from sqlalchemy.sql.expression import true, false, and_, text
|
||||||
@ -592,10 +592,6 @@ def save_cover_from_url(url, book_path):
|
|||||||
|
|
||||||
|
|
||||||
def save_cover_from_filestorage(filepath, saved_filename, img):
|
def save_cover_from_filestorage(filepath, saved_filename, img):
|
||||||
if hasattr(img,"metadata"):
|
|
||||||
img.save(filename=os.path.join(filepath, saved_filename))
|
|
||||||
img.close()
|
|
||||||
else:
|
|
||||||
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
|
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
|
||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
try:
|
try:
|
||||||
@ -604,6 +600,17 @@ def save_cover_from_filestorage(filepath, saved_filename, img):
|
|||||||
log.error(u"Failed to create path for cover")
|
log.error(u"Failed to create path for cover")
|
||||||
return False, _(u"Failed to create path for cover")
|
return False, _(u"Failed to create path for cover")
|
||||||
try:
|
try:
|
||||||
|
# upload of jgp file without wand
|
||||||
|
if isinstance(img, requests.Response):
|
||||||
|
with open(os.path.join(filepath, saved_filename), 'wb') as f:
|
||||||
|
f.write(img.content)
|
||||||
|
else:
|
||||||
|
if hasattr(img, "metadata"):
|
||||||
|
# upload of jpg/png... via url
|
||||||
|
img.save(filename=os.path.join(filepath, saved_filename))
|
||||||
|
img.close()
|
||||||
|
else:
|
||||||
|
# upload of jpg/png... from hdd
|
||||||
img.save(os.path.join(filepath, saved_filename))
|
img.save(os.path.join(filepath, saved_filename))
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
log.error(u"Cover-file is not a valid image file, or could not be stored")
|
log.error(u"Cover-file is not a valid image file, or could not be stored")
|
||||||
|
Loading…
Reference in New Issue
Block a user