Skip to content

fix: stream Immich multipart upload to avoid OOM#1034

Merged
jaimetur merged 1 commit intojaimetur:mainfrom
zhijiee:fix/immich-upload-streaming-regression
Mar 16, 2026
Merged

fix: stream Immich multipart upload to avoid OOM#1034
jaimetur merged 1 commit intojaimetur:mainfrom
zhijiee:fix/immich-upload-streaming-regression

Conversation

@zhijiee
Copy link
Copy Markdown
Contributor

@zhijiee zhijiee commented Feb 23, 2026

Summary

This PR updates Immich asset uploads to use streamed multipart encoding to prevent high memory usage (and potential OOM) during uploads.

Closes #1033

Problem

Uploads to Immich were sent via requests.post(..., files=...) in ClassImmichPhotos.push_asset(...).
With large files and/or concurrent uploads, multipart payload handling could cause excessive RAM usage.

Changes

  • Switched Immich upload implementation in push_asset to streamed multipart using MultipartEncoder
  • Kept existing upload metadata fields and duplicate handling behavior unchanged
  • Preserved optional sidecar upload support
  • Ensured file handles are safely managed during upload (ExitStack)

Scope / Impact

This affects all upload flows that call ClassImmichPhotos.push_asset(...), including:

  • automatic migration uploads to Immich
  • album uploads
  • no-album uploads

Tests

  • Added focused regression tests:
    • tests/test_immich_upload_streaming.py
    • verifies multipart streaming is used
    • verifies no files= argument is used
    • verifies sidecar inclusion still works
  • Ran:
    • uv run python -m unittest tests.test_immich_upload_streaming
    • uv run python -m unittest (contains existing unrelated baseline failures)

@jaimetur jaimetur merged commit 8b0b68d into jaimetur:main Mar 16, 2026
@jaimetur
Copy link
Copy Markdown
Owner

Thanks for this PR. Already merged

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT]: stream Immich asset uploads to prevent OOM during automatic migration

2 participants