Remove existing media files if not media is detected within a post

main
Bob Mottram 2021-08-09 22:27:13 +01:00
parent 105b125559
commit e5c488031d
1 changed files with 10 additions and 0 deletions

View File

@ -932,6 +932,16 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
Returns the filename and attachment type
"""
if not mediaBytes:
if filenameBase:
# remove any existing files
extensionTypes = getImageExtensions()
for ex in extensionTypes:
possibleOtherFormat = filenameBase + '.' + ex
if os.path.isfile(possibleOtherFormat):
os.remove(possibleOtherFormat)
if os.path.isfile(filenameBase):
os.remove(filenameBase)
if debug:
print('DEBUG: No media found within POST')
return None, None