Skip to content

fix(upload): store relative paths in uploaded_files.storage_path#234

Closed
tanbro wants to merge 0 commit into
xorbitsai:mainfrom
tanbro:fix/upload_relative_path
Closed

fix(upload): store relative paths in uploaded_files.storage_path#234
tanbro wants to merge 0 commit into
xorbitsai:mainfrom
tanbro:fix/upload_relative_path

Conversation

@tanbro

@tanbro tanbro commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Abandoned

Previously, The uploaded_files table's storage_path field stored absolute file paths in the database, which causes issues when:

  • The database / data files is migrated to a different server
  • XAGENT_UPLOADS_DIR environment variable is changed
  • Backing up and restoring to a different location

Changes:

  • Add web.utils.file module with path conversion functions:
    • to_relative_path(): convert absolute to relative (without user_id prefix)
    • to_absolute_path(): convert relative to absolute
    • find_file_by_path(): query files with absolute/relative path compatibility
  • Add UploadedFile.absolute_path property that handles both absolute and relative paths for backward compatibility
  • Update all file creation locations to store relative paths:
    • web/api/files.py: file upload API
    • web/api/websocket.py: task output files (all locations)
    • web/api/kb.py: knowledge base file upload
    • core/workspace.py: agent workspace file registration
    • scripts/backfill_uploaded_files.py: backfill script
  • Update all file path queries to check both absolute and relative formats
  • Add migrate_uploads_file_abs_path.py script for migrating existing data
    • Only migrates paths that match current UPLOADS_DIR configuration
    • Safe to run multiple times (e.g., after changing XAGENT_UPLOADS_DIR)
  • Add tests to verify relative path storage for both regular upload and KB upload

Verified: New files created via agent now store relative paths like "web_task_37/output/fibonacci_polar_final.png" instead of absolute paths. Old records with absolute paths continue to work via backward compatibility logic.

@XprobeBot XprobeBot added the bug Something isn't working label Apr 1, 2026
@tanbro tanbro closed this Apr 1, 2026
@tanbro tanbro force-pushed the fix/upload_relative_path branch from a1bdb2f to d904e8f Compare April 1, 2026 03:40
@tanbro

tanbro commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

The PR is abandoned, see #235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants