🔗 fix: Correct file_id Extraction in Markdown File Download Links
#10492
+234
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a critical bug in the markdown file download link handler that prevented files from being downloaded correctly through markdown links.
The issue occurred in
MarkdownComponents.tsxwhere thefile_idandfilenamewere being extracted incorrectly from URLs in the formatfiles/{userId}/{file_id}. The.pop()method was applied twice in reverse order, causing:userIdto be assigned to thefile_idvariablefile_idto be used as thefilenameThis resulted in download failures with 404 errors because the API endpoint was being called with
/api/files/download/{userId}/{userId}instead of the correct/api/files/download/{userId}/{file_id}.Root cause: When splitting the URL path and using
.pop()twice, the values were extracted in reverse order (last element first, then second-to-last), inverting the userId and file_id.Solution:
parts[2]to get the correctfile_idchildren) as the filename for better UXchildrento theuseMemodependency array to properly track changesThis fix enables MCP tools and other integrations to serve files through LibreChat's download system using markdown links.
Change Type
Testing
Test Process
/app/uploads/{userId}/{filename}file_id: UUID v4user: MongoDB ObjectId matching the userfilepath:/uploads/{userId}/{filename}source:"local"[filename.ext](files/{userId}/{file_id})Test Configuration:
Expected Behavior
Before fix:
/api/files/download/{userId}/{userId}→ 404 errorAfter fix:
/api/files/download/{userId}/{file_id}→ File downloads successfullyChecklist