(fix:openai) image uplads, use lambda in process_files

This commit is contained in:
ManishMadan2882
2025-04-18 18:27:02 +05:30
parent 5aa51f5f36
commit c8efef8f04
3 changed files with 15 additions and 20 deletions

View File

@@ -100,4 +100,4 @@ class LocalStorage(BaseStorage):
if not os.path.exists(full_path):
raise FileNotFoundError(f"File not found: {full_path}")
return processor_func(file_path=full_path, **kwargs)
return processor_func(local_path=full_path, **kwargs)

View File

@@ -98,23 +98,23 @@ class S3Storage(BaseStorage):
path: Path to the file
processor_func: Function that processes the file
**kwargs: Additional arguments to pass to the processor function
Returns:
The result of the processor function
"""
import tempfile
import logging
if not self.file_exists(path):
raise FileNotFoundError(f"File not found in S3: {path}")
with tempfile.NamedTemporaryFile(suffix=os.path.splitext(path)[1], delete=True) as temp_file:
try:
# Download the file from S3 to the temporary file
self.s3.download_fileobj(self.bucket_name, path, temp_file)
temp_file.flush()
result = processor_func(file_path=temp_file.name, **kwargs)
return result
return processor_func(local_path=temp_file.name, **kwargs)
except Exception as e:
logging.error(f"Error processing S3 file {path}: {e}", exc_info=True)
raise