Skip to content

Commit cec4cd4

Browse files
committed
Fix bug with having two extensions
1 parent 4808607 commit cec4cd4

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ async def index():
1616

1717
@app.post("/upload")
1818
async def upload(file: UploadFile = File(...), authorized = Depends(checkCredentials)):
19-
if len(file.filename.split('.')) == 1: # Guess the extension if there is none
19+
_filename_len = len(file.filename.split('.'))
20+
if _filename_len == 1: # Guess the extension if there is none
2021
_file = await file.read()
2122
guessExt = util.extensionSolver.guessFileExtension(_file)
2223
guessMime = util.extensionSolver.guessMime(_file)
@@ -27,7 +28,7 @@ async def upload(file: UploadFile = File(...), authorized = Depends(checkCredent
2728
return {"error": configuration.ERROR_UNALLOWED_CONTENT}
2829
if authorized:
2930
if configuration.RANDOMIZED_FILENAMES:
30-
_extension = file.filename.split('.')[1].lower() # Save the extension of the file for upload
31+
_extension = file.filename.split('.')[_filename_len -1].lower() # Save the extension of the file for upload
3132
print(_extension)
3233
file.filename = filenameGenerator.generateName(5) +f".{_extension}"
3334
await uploadFile(file)

0 commit comments

Comments
 (0)