File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ async def index():
1616
1717@app .post ("/upload" )
1818async 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 )
You can’t perform that action at this time.
0 commit comments