[PR #14156] [CLOSED] feat: Add backend API for media uploads #13863

Closed
opened 2026-02-07 07:20:23 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jellyfin/jellyfin/pull/14156
Author: @sajjaddevel
Created: 5/22/2025
Status: Closed

Base: masterHead: feature/media-upload-backend


📝 Commits (2)

  • 07fb4a6 feat: Add backend API for media uploads
  • ee7725f feat: Add backend API for media uploads

📊 Changes

4 files changed (+860 additions, -0 deletions)

View changed files

📝 Emby.Server.Implementations/Library/LibraryManager.cs (+131 -0)
Jellyfin.Api/Controllers/MediaUploadController.cs (+86 -0)
tests/Jellyfin.Api.Tests/Controllers/MediaUploadControllerTests.cs (+186 -0)
tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManagerUploadTests.cs (+457 -0)

📄 Description

This commit introduces the backend functionality required for you to upload movies and TV shows directly through the UI.

Key changes include:

  1. New API Endpoint:

    • Created MediaUploadController.cs in Jellyfin.Api/Controllers.
    • Defined a POST /Media/Upload endpoint that accepts IFormFile, an optional libraryId (Guid), and an optional collectionType (string).
    • The endpoint is authorized and handles request validation.
  2. File Handling Logic in LibraryManager:

    • Added a new public method AddUploadedMediaFile to Emby.Server.Implementations/Library/LibraryManager.cs.
    • This method handles:
      • Validation of the uploaded file.
      • Determination of the target library path based on libraryId, collectionType, or a default library.
      • Sanitization of filenames and creation of target directories.
      • Saving the uploaded file to the determined library path.
      • Triggering a library scan (LibraryMonitor.ReportFileSystemChange) for the new file.
      • Queueing a metadata refresh (ProviderManager.QueueRefresh) for the target library.
      • Error handling and logging for various scenarios (IO errors, library not found, etc.).
  3. Unit Tests:

    • Created tests/Jellyfin.Api.Tests/Controllers/MediaUploadControllerTests.cs with tests for the API endpoint, covering successful uploads, invalid inputs, and error conditions.
    • Created tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManagerUploadTests.cs with tests for the AddUploadedMediaFile method, covering various scenarios like different ways of specifying the target library, file saving, error handling, and interactions with mocked dependencies (FileSystem, LibraryMonitor, ProviderManager).

This implementation provides the necessary backend support for the media upload feature. Frontend changes will be handled separately in the jellyfin-web repository.

Changes

Issues


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/jellyfin/jellyfin/pull/14156 **Author:** [@sajjaddevel](https://github.com/sajjaddevel) **Created:** 5/22/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `feature/media-upload-backend` --- ### 📝 Commits (2) - [`07fb4a6`](https://github.com/jellyfin/jellyfin/commit/07fb4a602964a2820ffa2e6cc6901993c4d28c5d) feat: Add backend API for media uploads - [`ee7725f`](https://github.com/jellyfin/jellyfin/commit/ee7725f3e331dacffb4be035d0aeb10ad77e6f7b) feat: Add backend API for media uploads ### 📊 Changes **4 files changed** (+860 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `Emby.Server.Implementations/Library/LibraryManager.cs` (+131 -0) ➕ `Jellyfin.Api/Controllers/MediaUploadController.cs` (+86 -0) ➕ `tests/Jellyfin.Api.Tests/Controllers/MediaUploadControllerTests.cs` (+186 -0) ➕ `tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManagerUploadTests.cs` (+457 -0) </details> ### 📄 Description This commit introduces the backend functionality required for you to upload movies and TV shows directly through the UI. Key changes include: 1. **New API Endpoint:** * Created `MediaUploadController.cs` in `Jellyfin.Api/Controllers`. * Defined a `POST /Media/Upload` endpoint that accepts `IFormFile`, an optional `libraryId` (Guid), and an optional `collectionType` (string). * The endpoint is authorized and handles request validation. 2. **File Handling Logic in LibraryManager:** * Added a new public method `AddUploadedMediaFile` to `Emby.Server.Implementations/Library/LibraryManager.cs`. * This method handles: * Validation of the uploaded file. * Determination of the target library path based on `libraryId`, `collectionType`, or a default library. * Sanitization of filenames and creation of target directories. * Saving the uploaded file to the determined library path. * Triggering a library scan (`LibraryMonitor.ReportFileSystemChange`) for the new file. * Queueing a metadata refresh (`ProviderManager.QueueRefresh`) for the target library. * Error handling and logging for various scenarios (IO errors, library not found, etc.). 3. **Unit Tests:** * Created `tests/Jellyfin.Api.Tests/Controllers/MediaUploadControllerTests.cs` with tests for the API endpoint, covering successful uploads, invalid inputs, and error conditions. * Created `tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManagerUploadTests.cs` with tests for the `AddUploadedMediaFile` method, covering various scenarios like different ways of specifying the target library, file saving, error handling, and interactions with mocked dependencies (FileSystem, LibraryMonitor, ProviderManager). This implementation provides the necessary backend support for the media upload feature. Frontend changes will be handled separately in the jellyfin-web repository. <!-- Ensure your title is short, descriptive, and in the imperative mood (Fix X, Change Y, instead of Fixed X, Changed Y). For a good inspiration of what to write in commit messages and PRs please review https://chris.beams.io/posts/git-commit/ and our documentation. --> **Changes** <!-- Describe your changes here in 1-5 sentences. --> **Issues** <!-- Tag any issues that this PR solves here. ex. Fixes # --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-07 07:20:23 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/jellyfin#13863