Update main.py
Browse files
main.py
CHANGED
|
@@ -98,26 +98,26 @@ async def set_api_key(api_key: APIKey):
|
|
| 98 |
## POST - /upload_file_on_server
|
| 99 |
@app.post("/upload_file_on_server")
|
| 100 |
async def upload_file_on_server(file: UploadFile = File(...)):
|
| 101 |
-
file_content = file.read() # Load the document
|
| 102 |
|
| 103 |
-
# Create a directory if it doesn't exist
|
| 104 |
data_dir = "/data"
|
| 105 |
-
# os.makedirs(data_dir, exist_ok=True)
|
| 106 |
|
| 107 |
-
# Create a temporary file in the data directory
|
| 108 |
-
with tempfile.NamedTemporaryFile(delete=False, dir=data_dir) as temp_file:
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
#
|
| 113 |
-
|
| 114 |
|
| 115 |
-
#
|
| 116 |
-
|
| 117 |
-
|
| 118 |
|
| 119 |
-
#
|
| 120 |
-
|
| 121 |
|
| 122 |
|
| 123 |
## POST - /load_file
|
|
|
|
| 98 |
## POST - /upload_file_on_server
|
| 99 |
@app.post("/upload_file_on_server")
|
| 100 |
async def upload_file_on_server(file: UploadFile = File(...)):
|
| 101 |
+
# file_content = file.read() # Load the document
|
| 102 |
|
| 103 |
+
# # Create a directory if it doesn't exist
|
| 104 |
data_dir = "/data"
|
| 105 |
+
# # os.makedirs(data_dir, exist_ok=True)
|
| 106 |
|
| 107 |
+
# # Create a temporary file in the data directory
|
| 108 |
+
# with tempfile.NamedTemporaryFile(delete=False, dir=data_dir) as temp_file:
|
| 109 |
+
# temp_file.write(file_content) # Write the uploaded file content to the temporary file
|
| 110 |
+
# temp_file_path = temp_file.name # Get the path of the temporary file
|
| 111 |
+
# return temp_file_path
|
| 112 |
+
# Save the uploaded file to the temporary directory
|
| 113 |
+
file_path = os.path.join(data_dir, file.filename)
|
| 114 |
|
| 115 |
+
# Save the uploaded file to a temporary location
|
| 116 |
+
with open(file_path, "wb") as buffer:
|
| 117 |
+
shutil.copyfileobj(file.file, buffer)
|
| 118 |
|
| 119 |
+
# Return a response
|
| 120 |
+
return {"filename": file.filename, "message": "File uploaded successfully"}
|
| 121 |
|
| 122 |
|
| 123 |
## POST - /load_file
|