fixed router, langflow files and processors to not use temp names
This commit is contained in:
parent
7d6feef999
commit
179a7403cc
3 changed files with 20 additions and 21 deletions
|
|
@ -189,19 +189,20 @@ async def upload_and_ingest_user_file(
|
|||
# Create temporary file for task processing
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
|
||||
# Read file content
|
||||
content = await upload_file.read()
|
||||
|
||||
# Create temporary file
|
||||
|
||||
# Create temporary file with the actual filename (not a temp prefix)
|
||||
# Store in temp directory but use the real filename
|
||||
temp_dir = tempfile.gettempdir()
|
||||
safe_filename = upload_file.filename.replace(" ", "_").replace("/", "_")
|
||||
temp_fd, temp_path = tempfile.mkstemp(
|
||||
suffix=f"_{safe_filename}"
|
||||
)
|
||||
temp_path = os.path.join(temp_dir, safe_filename)
|
||||
|
||||
|
||||
try:
|
||||
# Write content to temp file
|
||||
with os.fdopen(temp_fd, 'wb') as temp_file:
|
||||
with open(temp_path, 'wb') as temp_file:
|
||||
temp_file.write(content)
|
||||
|
||||
logger.debug("Created temporary file for task processing", temp_path=temp_path)
|
||||
|
|
|
|||
|
|
@ -114,20 +114,22 @@ async def langflow_upload_ingest_task(
|
|||
temp_file_paths = []
|
||||
|
||||
try:
|
||||
# Create temp directory reference once
|
||||
temp_dir = tempfile.gettempdir()
|
||||
|
||||
for upload_file in upload_files:
|
||||
# Read file content
|
||||
content = await upload_file.read()
|
||||
|
||||
# Create temporary file
|
||||
|
||||
# Create temporary file with the actual filename (not a temp prefix)
|
||||
# Store in temp directory but use the real filename
|
||||
safe_filename = upload_file.filename.replace(" ", "_").replace("/", "_")
|
||||
temp_fd, temp_path = tempfile.mkstemp(
|
||||
suffix=f"_{safe_filename}"
|
||||
)
|
||||
|
||||
temp_path = os.path.join(temp_dir, safe_filename)
|
||||
|
||||
# Write content to temp file
|
||||
with os.fdopen(temp_fd, 'wb') as temp_file:
|
||||
with open(temp_path, 'wb') as temp_file:
|
||||
temp_file.write(content)
|
||||
|
||||
|
||||
temp_file_paths.append(temp_path)
|
||||
|
||||
logger.debug(
|
||||
|
|
|
|||
|
|
@ -574,12 +574,8 @@ class LangflowFileProcessor(TaskProcessor):
|
|||
content = f.read()
|
||||
|
||||
# Create file tuple for upload
|
||||
temp_filename = os.path.basename(item)
|
||||
# Extract original filename from temp file suffix (remove tmp prefix)
|
||||
if "_" in temp_filename:
|
||||
filename = temp_filename.split("_", 1)[1] # Get everything after first _
|
||||
else:
|
||||
filename = temp_filename
|
||||
# The temp file now has the actual filename, no need to extract it
|
||||
filename = os.path.basename(item)
|
||||
content_type, _ = mimetypes.guess_type(filename)
|
||||
if not content_type:
|
||||
content_type = 'application/octet-stream'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue