fluttercandies / flutter_photo_manager

A Flutter plugin that provides images, videos, and audio abstraction management APIs without interface integration, available on Android, iOS, macOS and OpenHarmony.
https://pub.dev/packages/photo_manager
Apache License 2.0
694 stars 315 forks source link

[Bug report] Saving a raw image may result in a different checksum compared to the original raw image #1193

Closed dvbthien closed 1 month ago

dvbthien commented 1 month ago

Version

3.5.0

Platforms

iOS

Device Model

iPhone XS (IOS 15)

flutter info

[✓] Flutter (Channel stable, 3.24.3, on macOS 15.0 24A335 darwin-arm64, locale
    en-VN)
    • Flutter version 3.24.3 on channel stable at
      /Users/winlun/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (3 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit https://flutter.dev/to/macos-android-setup for detailed
      instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.15.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at
    /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/to/macos-android-setup for detailed
      instructions).

[✓] VS Code (version 1.93.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.98.0

[✓] Connected device (2 available)
    • macOS (desktop)                 • macos                 • darwin-arm64 •
      macOS 15.0 24A335 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin       •
      macOS 15.0 24A335 darwin-arm64

[✓] Network resources
    • All expected network resources are available.

How to reproduce?

Hi @AlexV525,

The Immich mobile uses this package to save remote images to the gallery on iOS. However, when I downloaded a remote image on iOS 15.1, the locally downloaded image had a different checksum than the remote image. As a result, Immich on mobile displayed two images: one local image and one remote image. It only happens with images.

After investigating the problem, it seems that photo_manager uses PHAssetCreationRequest in saveImageWithPath to create a new Photos asset, which sometimes changes the info metadata and results in a file with a different hash. Can you add creationRequestForAssetFromImageAtFileURL and creationRequestForAssetFromVideoAtFileURL to add raw assets to the gallery without changing the checksum?

I really appreciate you taking the time to read this.

Logs

No response

Example code (optional)

No response

Contact

No response

AlexV525 commented 1 month ago

Happy to, but we should figure out if there is a side effect for the saving method.

dvbthien commented 1 month ago

I've already tried and haven't found any major issues. The assets are saved with the same checksum. You can investigate side effect further.

More information: When I download a remote image on iOS 16.7 from a different iPhone, I download the same remote image without issue. However, the problem persists when the image is a .jpg taken with an iPhone. PHAssetCreationRequest may work differently on each iOS version.

Your package is excellent. Thank you for your dedication.

AlexV525 commented 1 month ago

@dvbthien Could you verify if https://github.com/fluttercandies/flutter_photo_manager/pull/1194 fixes the issue?

dvbthien commented 1 month ago

@AlexV525 I'll test it and let you know soon. Thanks

dvbthien commented 1 month ago

Hi @AlexV525, I have tested it, and it works perfectly. The issue has been resolved.