Fix WriteToStreamAsync not preserving EXIF data on Android - #15
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 vianew ExifInterface( but the changes were silently lost.outputStream)Root Cause
AndroidX
ExifInterfaceis 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
WriteToFileAsyncalready uses successfully:ExifInterfacefrom the file path (reliable)SaveAttributes()This implements the workaround callers no longer need to manually write to a file and reload.transparently
Testing
Verified structurally against the working
WriteToFileAsyncpattern. 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