File size: 477 Bytes
e1d6e8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import os
from pathlib import Path
def save_upload_temp(upload_file, dest_dir: str = ".tmp_uploads") -> str:
Path(dest_dir).mkdir(parents=True, exist_ok=True)
filename = upload_file.filename
dest_path = os.path.join(dest_dir, filename)
with open(dest_path, "wb") as f:
f.write(upload_file.file.read())
return dest_path
def read_file_text(path: str) -> str:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
return f.read()
|