Skip to content

Commit 83d97bd

Browse files
shubham-padianiranjan94
authored andcommitted
fix image upload in placeholders section (#2678)
1 parent 569a4f7 commit 83d97bd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/views/super_admin/content.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import os
33
import shutil
4+
import errno
45

56
import PIL
67
from PIL import Image
@@ -71,15 +72,20 @@ def placeholder_upload():
7172
wpercent = (basewidth / float(img.size[0]))
7273
hsize = int((float(img.size[1]) * float(wpercent)))
7374
img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
74-
os.mkdir(app.config['TEMP_UPLOADS_FOLDER'])
75+
try:
76+
os.mkdir(app.config['TEMP_UPLOADS_FOLDER'])
77+
except OSError as exc:
78+
if exc.errno != errno.EEXIST:
79+
raise exc
80+
pass
7581
img.save(app.config['TEMP_UPLOADS_FOLDER'] + '/temp.png')
7682
file_name = temp_img_file.rsplit('/', 1)[1]
7783
thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name)
7884
background_thumbnail_url = upload(
7985
thumbnail_file,
8086
'placeholders/thumbnail/' + filename
8187
)
82-
shutil.rmtree(path=app.config['TEMP_UPLOADS_FOLDER'] + '/temp/')
88+
shutil.rmtree(path=app.config['TEMP_UPLOADS_FOLDER'])
8389
placeholder_db = DataGetter.get_custom_placeholder_by_name(request.form['name'])
8490
if placeholder_db:
8591
placeholder_db.url = placeholder

0 commit comments

Comments
 (0)