File size: 519 Bytes
ecb69bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os
import shutil
import tempfile


def save_uploaded_file(uploaded_path: str) -> str:
    temp_dir = tempfile.mkdtemp()
    filename = os.path.basename(uploaded_path)
    new_path = os.path.join(temp_dir, filename)
    shutil.copy(uploaded_path, new_path)
    return new_path


def read_text_file(file_path: str) -> str:
    try:
        with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
            return f.read()
    except Exception as e:
        return f"Could not read text file: {str(e)}"