From f100732e4d8344500e6550d3ab10e77feda015f5 Mon Sep 17 00:00:00 2001 From: BBaoVanC Date: Tue, 15 Sep 2020 17:20:41 -0500 Subject: [PATCH] Check if image with same name already exists --- imgupload.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/imgupload.py b/imgupload.py index 1d3c120..95f69d9 100644 --- a/imgupload.py +++ b/imgupload.py @@ -73,6 +73,9 @@ def upload(): if f: # if the uploaded image exists print("Uploaded image exists") + if Path(os.path.join(settings.UPLOAD_FOLDER, fname)).is_file(): + print("Requested filename already exists!") + return jsonify({'status': 'error', 'error': 'FILENAME_TAKEN'}), status.HTTP_409_CONFLICT f.save(os.path.join(settings.UPLOAD_FOLDER, fname)) # save the image print("Saved to {0}".format(fname)) url = settings.ROOTURL + fname # construct the url to the image