We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 824f17f commit 30f0118Copy full SHA for 30f0118
app/api/v1/endpoints/article.py
@@ -18,7 +18,12 @@
18
19
@router.post("/uploadToSelfFolder", response_model="dict")
20
async def upload_to_self_folder(folder_id: int = Query(...), article: UploadFile = File(...), db: AsyncSession = Depends(get_db)):
21
- # 由前端保证上传的为 PDF
+ # 检查上传的必须为 PDF
22
+ head = await article.read(5) # 读取文件的前 5 个字节,用于魔数检测
23
+ if not head.startswith(b"%PDF-"):
24
+ raise HTTPException(status_code=405, detail="File uploaded must be a PDF.")
25
+ await article.seek(0) # 重置文件指针位置
26
+
27
# 用文件名(不带扩展名)作为 Article 名称
28
name = os.path.splitext(article.filename)[0]
29
0 commit comments