Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -258,25 +258,27 @@ def create_app():
|
|
| 258 |
thread.start()
|
| 259 |
return "OK", 200
|
| 260 |
|
| 261 |
-
@flask_app.route("/upload", methods=["POST","GET"])
|
| 262 |
def upload():
|
| 263 |
-
|
| 264 |
if request.method == 'POST':
|
| 265 |
-
file = request.files
|
| 266 |
if not file:
|
| 267 |
return "No file uploaded", 400
|
| 268 |
if file and file.filename.endswith('.db'):
|
| 269 |
-
|
|
|
|
| 270 |
file.save(db_path)
|
| 271 |
-
|
| 272 |
# Convert the file path to an absolute path and reinitialize the agent_app
|
| 273 |
abs_file_path = os.path.abspath(db_path)
|
| 274 |
global agent_app
|
| 275 |
agent_app = create_agent_app(abs_file_path)
|
| 276 |
-
|
| 277 |
-
|
|
|
|
| 278 |
socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
|
| 279 |
return redirect(url_for("index")) # Go back to index page
|
|
|
|
| 280 |
return render_template("upload.html")
|
| 281 |
|
| 282 |
return flask_app, socketio
|
|
|
|
| 258 |
thread.start()
|
| 259 |
return "OK", 200
|
| 260 |
|
| 261 |
+
@flask_app.route("/upload", methods=["POST", "GET"])
|
| 262 |
def upload():
|
|
|
|
| 263 |
if request.method == 'POST':
|
| 264 |
+
file = request.files.get('file')
|
| 265 |
if not file:
|
| 266 |
return "No file uploaded", 400
|
| 267 |
if file and file.filename.endswith('.db'):
|
| 268 |
+
# Use flask_app.config instead of app.config
|
| 269 |
+
db_path = os.path.join(flask_app.config['UPLOAD_FOLDER'], 'uploaded.db')
|
| 270 |
file.save(db_path)
|
| 271 |
+
|
| 272 |
# Convert the file path to an absolute path and reinitialize the agent_app
|
| 273 |
abs_file_path = os.path.abspath(db_path)
|
| 274 |
global agent_app
|
| 275 |
agent_app = create_agent_app(abs_file_path)
|
| 276 |
+
|
| 277 |
+
# Use an f-string properly to log the uploaded file name
|
| 278 |
+
print(f"[INFO_PRINT]: Database file '{file.filename}' uploaded and loaded.")
|
| 279 |
socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
|
| 280 |
return redirect(url_for("index")) # Go back to index page
|
| 281 |
+
# For GET requests, simply render the upload form.
|
| 282 |
return render_template("upload.html")
|
| 283 |
|
| 284 |
return flask_app, socketio
|