Spaces:
Sleeping
Sleeping
Fix Cloudinary file upload issues: Add file existence checks, better error handling, and detailed logging for upload debugging
Browse files- app.py +56 -22
- utils/cloudinary_client.py +12 -0
app.py
CHANGED
|
@@ -334,18 +334,35 @@ async def process_text_to_3d(job_id: str, prompt: str, user_id: Optional[str]):
|
|
| 334 |
|
| 335 |
job_manager.update_job_progress(job_id, "uploading_results", 90, "Uploading 3D model...")
|
| 336 |
|
| 337 |
-
#
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
depth_result['obj_path'],
|
| 341 |
-
f"model_{job_id}.obj"
|
| 342 |
-
)
|
| 343 |
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
# Complete job
|
| 351 |
job_manager.complete_job(job_id, {
|
|
@@ -393,18 +410,35 @@ async def process_upload_to_3d(job_id: str, file_content: bytes, filename: str,
|
|
| 393 |
|
| 394 |
job_manager.update_job_progress(job_id, "uploading_results", 90, "Uploading 3D model...")
|
| 395 |
|
| 396 |
-
#
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
depth_result['obj_path'],
|
| 400 |
-
f"model_{job_id}.obj"
|
| 401 |
-
)
|
| 402 |
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
|
| 409 |
# Complete job
|
| 410 |
job_manager.complete_job(job_id, {
|
|
|
|
| 334 |
|
| 335 |
job_manager.update_job_progress(job_id, "uploading_results", 90, "Uploading 3D model...")
|
| 336 |
|
| 337 |
+
# Check if files exist before uploading
|
| 338 |
+
if not os.path.exists(depth_result['obj_path']):
|
| 339 |
+
raise FileNotFoundError(f"OBJ file not found: {depth_result['obj_path']}")
|
|
|
|
|
|
|
|
|
|
| 340 |
|
| 341 |
+
if not os.path.exists(depth_result['depth_map_path']):
|
| 342 |
+
raise FileNotFoundError(f"Depth map file not found: {depth_result['depth_map_path']}")
|
| 343 |
+
|
| 344 |
+
logger.info(f"π Files exist - OBJ: {depth_result['obj_path']}, Depth: {depth_result['depth_map_path']}")
|
| 345 |
+
|
| 346 |
+
# Upload results with better error handling
|
| 347 |
+
try:
|
| 348 |
+
model_url = await asyncio.to_thread(
|
| 349 |
+
cloudinary_client.upload_file,
|
| 350 |
+
depth_result['obj_path'],
|
| 351 |
+
f"model_{job_id}.obj"
|
| 352 |
+
)
|
| 353 |
+
except Exception as e:
|
| 354 |
+
logger.error(f"β Failed to upload OBJ file: {str(e)}")
|
| 355 |
+
raise e
|
| 356 |
+
|
| 357 |
+
try:
|
| 358 |
+
depth_map_url = await asyncio.to_thread(
|
| 359 |
+
cloudinary_client.upload_image_from_path,
|
| 360 |
+
depth_result['depth_map_path'],
|
| 361 |
+
f"depth_{job_id}"
|
| 362 |
+
)
|
| 363 |
+
except Exception as e:
|
| 364 |
+
logger.error(f"β Failed to upload depth map: {str(e)}")
|
| 365 |
+
raise e
|
| 366 |
|
| 367 |
# Complete job
|
| 368 |
job_manager.complete_job(job_id, {
|
|
|
|
| 410 |
|
| 411 |
job_manager.update_job_progress(job_id, "uploading_results", 90, "Uploading 3D model...")
|
| 412 |
|
| 413 |
+
# Check if files exist before uploading
|
| 414 |
+
if not os.path.exists(depth_result['obj_path']):
|
| 415 |
+
raise FileNotFoundError(f"OBJ file not found: {depth_result['obj_path']}")
|
|
|
|
|
|
|
|
|
|
| 416 |
|
| 417 |
+
if not os.path.exists(depth_result['depth_map_path']):
|
| 418 |
+
raise FileNotFoundError(f"Depth map file not found: {depth_result['depth_map_path']}")
|
| 419 |
+
|
| 420 |
+
logger.info(f"π Files exist - OBJ: {depth_result['obj_path']}, Depth: {depth_result['depth_map_path']}")
|
| 421 |
+
|
| 422 |
+
# Upload results with better error handling
|
| 423 |
+
try:
|
| 424 |
+
model_url = await asyncio.to_thread(
|
| 425 |
+
cloudinary_client.upload_file,
|
| 426 |
+
depth_result['obj_path'],
|
| 427 |
+
f"model_{job_id}.obj"
|
| 428 |
+
)
|
| 429 |
+
except Exception as e:
|
| 430 |
+
logger.error(f"β Failed to upload OBJ file: {str(e)}")
|
| 431 |
+
raise e
|
| 432 |
+
|
| 433 |
+
try:
|
| 434 |
+
depth_map_url = await asyncio.to_thread(
|
| 435 |
+
cloudinary_client.upload_image_from_path,
|
| 436 |
+
depth_result['depth_map_path'],
|
| 437 |
+
f"depth_{job_id}"
|
| 438 |
+
)
|
| 439 |
+
except Exception as e:
|
| 440 |
+
logger.error(f"β Failed to upload depth map: {str(e)}")
|
| 441 |
+
raise e
|
| 442 |
|
| 443 |
# Complete job
|
| 444 |
job_manager.complete_job(job_id, {
|
utils/cloudinary_client.py
CHANGED
|
@@ -80,6 +80,17 @@ class CloudinaryClient:
|
|
| 80 |
try:
|
| 81 |
logger.info(f"βοΈ Uploading file to Cloudinary: {public_id}")
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
result = cloudinary.uploader.upload(
|
| 84 |
file_path,
|
| 85 |
public_id=f"text-to-3d/{public_id}",
|
|
@@ -94,6 +105,7 @@ class CloudinaryClient:
|
|
| 94 |
|
| 95 |
except Exception as e:
|
| 96 |
logger.error(f"β Error uploading file to Cloudinary: {str(e)}")
|
|
|
|
| 97 |
raise e
|
| 98 |
|
| 99 |
def delete_file(self, public_id: str, resource_type: str = "image") -> bool:
|
|
|
|
| 80 |
try:
|
| 81 |
logger.info(f"βοΈ Uploading file to Cloudinary: {public_id}")
|
| 82 |
|
| 83 |
+
# Check if file exists and is accessible
|
| 84 |
+
if not os.path.exists(file_path):
|
| 85 |
+
raise FileNotFoundError(f"File not found: {file_path}")
|
| 86 |
+
|
| 87 |
+
file_size = os.path.getsize(file_path)
|
| 88 |
+
logger.info(f"π File info - Path: {file_path}, Size: {file_size} bytes")
|
| 89 |
+
|
| 90 |
+
# Verify file is readable
|
| 91 |
+
with open(file_path, 'rb') as f:
|
| 92 |
+
f.read(1) # Try to read first byte
|
| 93 |
+
|
| 94 |
result = cloudinary.uploader.upload(
|
| 95 |
file_path,
|
| 96 |
public_id=f"text-to-3d/{public_id}",
|
|
|
|
| 105 |
|
| 106 |
except Exception as e:
|
| 107 |
logger.error(f"β Error uploading file to Cloudinary: {str(e)}")
|
| 108 |
+
logger.error(f"π Failed file path: {file_path}")
|
| 109 |
raise e
|
| 110 |
|
| 111 |
def delete_file(self, public_id: str, resource_type: str = "image") -> bool:
|