samwaugh commited on
Commit
2c9a398
Β·
1 Parent(s): 6c3368c

try again

Browse files
Files changed (1) hide show
  1. 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
- print(f"πŸ“€ Upload request for run {run_id}")
194
-
195
- if "file" not in request.files:
196
- print(f"❌ No file in request for run {run_id}")
197
- return jsonify({"error": "no-file"}), 400
198
- file = request.files["file"]
199
- # Ensure artifacts directory exists
200
- os.makedirs(ARTIFACTS_DIR, exist_ok=True)
201
- # Save the file as artifacts/<runId>.jpg
202
- file_path = os.path.join(ARTIFACTS_DIR, f"{run_id}.jpg")
203
- print(f"πŸ“€ Saving file to {file_path}")
204
- file.save(file_path)
205
- # Check file exists otherwise 400
206
- if not os.path.exists(file_path):
207
- print(f"❌ File not saved for run {run_id}")
208
- return jsonify({"error": "file-not-saved"}), 500
209
- print(f"βœ… File saved successfully for run {run_id}")
210
- # Respond with 204 No Content (success, no response body)
211
- return "{}", 204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"])