try again
Browse files- backend/runner/app.py +44 -19
backend/runner/app.py
CHANGED
|
@@ -190,25 +190,50 @@ def upload_file(run_id: str):
|
|
| 190 |
"""
|
| 191 |
Receives the image file upload for the given runId and saves it to disk.
|
| 192 |
"""
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
|
| 214 |
@app.route("/runs", methods=["POST"])
|
|
|
|
| 190 |
"""
|
| 191 |
Receives the image file upload for the given runId and saves it to disk.
|
| 192 |
"""
|
| 193 |
+
try:
|
| 194 |
+
print(f"π€ Upload request for run {run_id}")
|
| 195 |
+
|
| 196 |
+
if "file" not in request.files:
|
| 197 |
+
print(f"β No file in request for run {run_id}")
|
| 198 |
+
return jsonify({"error": "no-file"}), 400
|
| 199 |
+
|
| 200 |
+
file = request.files["file"]
|
| 201 |
+
print(f"π€ File received: {file.filename}, size: {file.content_length if hasattr(file, 'content_length') else 'unknown'}")
|
| 202 |
+
|
| 203 |
+
# Ensure artifacts directory exists
|
| 204 |
+
try:
|
| 205 |
+
os.makedirs(ARTIFACTS_DIR, exist_ok=True)
|
| 206 |
+
print(f"π€ Artifacts directory: {ARTIFACTS_DIR} (exists: {os.path.exists(ARTIFACTS_DIR)})")
|
| 207 |
+
except Exception as e:
|
| 208 |
+
print(f"β Failed to create artifacts directory: {e}")
|
| 209 |
+
return jsonify({"error": f"directory-creation-failed: {str(e)}"}), 500
|
| 210 |
+
|
| 211 |
+
# Save the file as artifacts/<runId>.jpg
|
| 212 |
+
file_path = os.path.join(ARTIFACTS_DIR, f"{run_id}.jpg")
|
| 213 |
+
print(f"π€ Saving file to {file_path}")
|
| 214 |
+
|
| 215 |
+
try:
|
| 216 |
+
file.save(file_path)
|
| 217 |
+
except Exception as e:
|
| 218 |
+
print(f"β Failed to save file: {e}")
|
| 219 |
+
return jsonify({"error": f"file-save-failed: {str(e)}"}), 500
|
| 220 |
+
|
| 221 |
+
# Check file exists otherwise 500
|
| 222 |
+
if not os.path.exists(file_path):
|
| 223 |
+
print(f"β File not saved for run {run_id}")
|
| 224 |
+
return jsonify({"error": "file-not-saved"}), 500
|
| 225 |
+
|
| 226 |
+
file_size = os.path.getsize(file_path)
|
| 227 |
+
print(f"β
File saved successfully for run {run_id}, size: {file_size} bytes")
|
| 228 |
+
|
| 229 |
+
# Respond with 204 No Content (success, no response body)
|
| 230 |
+
return "{}", 204
|
| 231 |
+
|
| 232 |
+
except Exception as e:
|
| 233 |
+
print(f"β Unexpected error in upload_file: {e}")
|
| 234 |
+
import traceback
|
| 235 |
+
traceback.print_exc()
|
| 236 |
+
return jsonify({"error": f"unexpected-error: {str(e)}"}), 500
|
| 237 |
|
| 238 |
|
| 239 |
@app.route("/runs", methods=["POST"])
|