Browse Source

add upload exception

ming 3 years ago
parent
commit
25ad668dbc
1 changed files with 3 additions and 2 deletions
  1. 3 2
      api/main.py

+ 3 - 2
api/main.py

@@ -120,14 +120,15 @@ async def create_upload_file(file: UploadFile = File(...)):
     try:
         if file.content_type=='video/mp4':
             async with aiofiles.open(img_upload_folder+img_name+'.mp4', 'wb') as out_file:
-                content = await in_file.read()
+                content = await file.read()
                 await out_file.write(content) 
         else:
             contents = await file.read()
             image = Image.open(io.BytesIO(contents))
             image= image.convert("RGB")
             image.save(img_upload_folder+img_name+'.jpg')
-    except:
+    except Exception as e:
+        logging.error(traceback.format_exc())
         return {'msg':'檔案無法使用'}
     return {"msg": 'www.choozmo.com:8168/'+tmp_img_sub_folder+img_name+'.jpg'}