Skip to content

Fix WriteToStreamAsync not preserving EXIF data on Android - #15

Merged
jfversluis merged 1 commit into
mainfrom
fix/write-to-stream-preserves-exif
May 8, 2026
Merged

Fix WriteToStreamAsync not preserving EXIF data on Android#15
jfversluis merged 1 commit into
mainfrom
fix/write-to-stream-preserves-exif

Conversation

@jfversluis

Copy link
Copy Markdown
Owner

Description

Fixes #13

The Android ExifInterface.SaveAttributes() does not reliably persist EXIF modifications when operating directly on streams. The previous implementation copied the input to the output stream, then tried to modify it in-place via new ExifInterface( but the changes were silently lost.outputStream)

Root Cause

AndroidX ExifInterface is designed primarily for file-based operations. When constructed from a stream, SaveAttributes() either doesn't flush correctly or the stream's internal state becomes inconsistent. This is a known limitation of the AndroidX library.

Fix

Use the same temp-file approach that WriteToFileAsync already uses successfully:

  1. Write the input stream to a temporary file
  2. Create ExifInterface from the file path (reliable)
  3. Set attributes and call SaveAttributes()
  4. Copy the modified file to the output stream
  5. Clean up the temp file

This implements the workaround callers no longer need to manually write to a file and reload.transparently

Testing

Verified structurally against the working WriteToFileAsync pattern. The fix applies the exact same code path that already works, just with an intermediate temp file for the stream case.

Breaking Changes

same API, correct behavior now.None

The Android ExifInterface.SaveAttributes() does not reliably persist EXIF
modifications when operating directly on streams. The previous implementation
copied the input stream to the output stream and then tried to modify the
output stream in-place via ExifInterface, but the changes were lost.

The fix uses the same temp-file approach that WriteToFileAsync already uses
successfully:
1. Write the input stream to a temporary file
2. Create ExifInterface from the file path (reliable)
3. Set attributes and call SaveAttributes()
4. Copy the modified file content to the output stream
5. Clean up the temp file

This matches the workaround described in the issue (use WriteToFile and
reload) but implements it transparently inside WriteToStreamAsync so callers
don't need to work around it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jfversluis
jfversluis merged commit 5044bdb into main May 8, 2026
2 checks passed
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.

Writing data to stream doesn't preserve the exif data

1 participant