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
|
|
@ -193,15 +193,16 @@ async def upload_and_ingest_user_file(
|
||||||
# Read file content
|
# Read file content
|
||||||
content = await upload_file.read()
|
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("/", "_")
|
safe_filename = upload_file.filename.replace(" ", "_").replace("/", "_")
|
||||||
temp_fd, temp_path = tempfile.mkstemp(
|
temp_path = os.path.join(temp_dir, safe_filename)
|
||||||
suffix=f"_{safe_filename}"
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Write content to temp file
|
# 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.write(content)
|
||||||
|
|
||||||
logger.debug("Created temporary file for task processing", temp_path=temp_path)
|
logger.debug("Created temporary file for task processing", temp_path=temp_path)
|
||||||
|
|
|
||||||
|
|
@ -114,18 +114,20 @@ async def langflow_upload_ingest_task(
|
||||||
temp_file_paths = []
|
temp_file_paths = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Create temp directory reference once
|
||||||
|
temp_dir = tempfile.gettempdir()
|
||||||
|
|
||||||
for upload_file in upload_files:
|
for upload_file in upload_files:
|
||||||
# Read file content
|
# Read file content
|
||||||
content = await upload_file.read()
|
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("/", "_")
|
safe_filename = upload_file.filename.replace(" ", "_").replace("/", "_")
|
||||||
temp_fd, temp_path = tempfile.mkstemp(
|
temp_path = os.path.join(temp_dir, safe_filename)
|
||||||
suffix=f"_{safe_filename}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Write content to temp file
|
# 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.write(content)
|
||||||
|
|
||||||
temp_file_paths.append(temp_path)
|
temp_file_paths.append(temp_path)
|
||||||
|
|
|
||||||
|
|
@ -574,12 +574,8 @@ class LangflowFileProcessor(TaskProcessor):
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
# Create file tuple for upload
|
# Create file tuple for upload
|
||||||
temp_filename = os.path.basename(item)
|
# The temp file now has the actual filename, no need to extract it
|
||||||
# Extract original filename from temp file suffix (remove tmp prefix)
|
filename = os.path.basename(item)
|
||||||
if "_" in temp_filename:
|
|
||||||
filename = temp_filename.split("_", 1)[1] # Get everything after first _
|
|
||||||
else:
|
|
||||||
filename = temp_filename
|
|
||||||
content_type, _ = mimetypes.guess_type(filename)
|
content_type, _ = mimetypes.guess_type(filename)
|
||||||
if not content_type:
|
if not content_type:
|
||||||
content_type = 'application/octet-stream'
|
content_type = 'application/octet-stream'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue