fix: disallow empty files

This commit is contained in:
JoeyShapiro 2024-10-10 15:33:27 -05:00
parent ad31bd51fd
commit df824db042
2 changed files with 11 additions and 0 deletions

View File

@ -47,6 +47,12 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)):
file_path = f"{UPLOAD_DIR}/{filename}"
contents = file.file.read()
if len(contents) == 0:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=ERROR_MESSAGES.EMPTY_CONTENT,
)
with open(file_path, "wb") as f:
f.write(contents)
f.close()

View File

@ -115,6 +115,11 @@
itemId: tempItemId
};
if (fileItem.size == 0) {
toast.error($i18n.t('File must have content to be uploaded'));
return null;
}
knowledge.files = [...(knowledge.files ?? []), fileItem];
// Check if the file is an audio file and transcribe/convert it to text file