Skip to content

Commit

Permalink
Merge pull request #1422 from fadingNA/multiple-files-bug
Browse files Browse the repository at this point in the history
upload routes fix for multiple upload
  • Loading branch information
dartpain authored Nov 14, 2024
2 parents c97968f + 91e7c16 commit 1decff2
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions application/api/user/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,34 @@ def post(self):
for file in files:
filename = secure_filename(file.filename)
file.save(os.path.join(temp_dir, filename))

print(f"Saved file: {filename}")
zip_path = shutil.make_archive(
base_name=os.path.join(save_dir, job_name),
format="zip",
root_dir=temp_dir,
)
final_filename = os.path.basename(zip_path)
shutil.rmtree(temp_dir)
task = ingest.delay(
settings.UPLOAD_FOLDER,
[
".rst",
".md",
".pdf",
".txt",
".docx",
".csv",
".epub",
".html",
".mdx",
".json",
".xlsx",
".pptx",
],
job_name,
final_filename,
user,
)
else:
file = files[0]
final_filename = secure_filename(file.filename)
Expand All @@ -350,9 +370,10 @@ def post(self):
final_filename,
user,
)

except Exception as err:
print(f"Error: {err}")
return make_response(jsonify({"success": False, "error": str(err)}), 400)

return make_response(jsonify({"success": True, "task_id": task.id}), 200)


Expand Down Expand Up @@ -423,6 +444,11 @@ def get(self):

task = celery.AsyncResult(task_id)
task_meta = task.info
print(f"Task status: {task.status}")
if not isinstance(
task_meta, (dict, list, str, int, float, bool, type(None))
):
task_meta = str(task_meta) # Convert to a string representation
except Exception as err:
return make_response(jsonify({"success": False, "error": str(err)}), 400)

Expand Down

0 comments on commit 1decff2

Please sign in to comment.