Check if image with same name already exists

This commit is contained in:
BBaoVanC 2020-09-15 17:20:41 -05:00
parent 46420eecda
commit f100732e4d
No known key found for this signature in database
GPG Key ID: 6D74C8B0E7D791C2
1 changed files with 3 additions and 0 deletions

View File

@ -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