[PR #27957] feat(api): add file deletion endpoint to remove uploaded files by ID #31910

Open
opened 2026-02-21 20:50:23 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/27957

State: open
Merged: No


Summary

close #27420

Added API for deleting uploaded files and related DB entries by unique ID:
DELETE /v1/files/{file_id}.

The API reuses the FileService.delete_file interface here.

However, there is a session scope bug in the delete_file function discussed in #27905. Please kindly review and merge #27911 and #27948 before this PR. Thank you very much!

cc @Himmelskomiker, thanks for raising the issue and the suggestion!

Example Testing Commands

curl -X DELETE "http://localhost:5001/v1/files/$FILE_ID" \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"user": "abc-123"}

Expected outcomes:

204 No Content: File successfully deleted
401 Unauthorized: Invalid or missing API key in the Authorization header
404 Not Found: File with the specified file_id does not exist

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/27957 **State:** open **Merged:** No --- ## Summary close #27420 Added API for deleting uploaded files and related DB entries by unique ID: `DELETE /v1/files/{file_id}`. The API reuses the `FileService.delete_file` interface [here](https://github.com/langgenius/dify/blob/main/api/services/file_service.py#L238). However, there is a session scope bug in the `delete_file` function discussed in #27905. Please kindly review and merge #27911 and #27948 before this PR. Thank you very much! cc @Himmelskomiker, thanks for raising the issue and the suggestion! ## Example Testing Commands ```bash curl -X DELETE "http://localhost:5001/v1/files/$FILE_ID" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{"user": "abc-123"} ``` **Expected outcomes:** **204 No Content**: File successfully deleted **401 Unauthorized**: Invalid or missing API key in the Authorization header **404 Not Found**: File with the specified file_id does not exist ## Checklist - [x] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:50:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31910