vella-backend / _utils /handle_files.py
luanpoppe
feat: adicionando url.py em cada app e mais refatorações
12b0dd7
raw
history blame
731 Bytes
import tempfile, os
def handle_pdf_files_from_serializer(files):
listaPDFs = []
for file in files:
file.seek(0)
with tempfile.NamedTemporaryFile(
delete=False, suffix=".pdf"
) as temp_file: # Create a temporary file to save the uploaded PDF
for (
chunk
) in file.chunks(): # Write the uploaded file content to the temporary file
temp_file.write(chunk)
temp_file_path = temp_file.name # Get the path of the temporary file
listaPDFs.append(temp_file_path)
print("listaPDFs: ", listaPDFs)
return listaPDFs
def remove_pdf_temp_files(listaPDFs):
for file in listaPDFs:
os.remove(file)