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
679 stars 307 forks source link

The requested file name is already in use. #1173

Open PBomermustekiin opened 2 months ago

PBomermustekiin commented 2 months ago

Version

3.1.1

Platforms

iOS

Device Model

iphone 15 pro max

flutter info

[✓] Flutter (Channel beta, 3.22.0-0.3.pre, on macOS 14.4.1 23E224 darwin-arm64, locale tr-TR)
    • Flutter version 3.22.0-0.3.pre on channel beta at /Users/omer/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 87b652410d (3 months ago), 2024-04-23 21:41:18 -0500
    • Engine revision b4bfd45986
    • Dart version 3.4.0 (build 3.4.0-282.3.beta)
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/omer/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

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

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] Connected device (4 available)
    • Ömer iPhone 14 Pro Max (mobile) • 00008120-001A25803487C01E • ios            • iOS 17.6 21G80
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 127.0.6533.89

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

• No issues found!

How to reproduce?

when i try to order by videos sizes, getting that error just for some devices, not always.

Logs

PlatformException(Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo={NSLocalizedRecoverySuggestion=The requested file name is already in use. Try a different file name or location., NSLocalizedDescription=Cannot Save, NSUnderlyingError=0x300141aa0 {Error Domain=NSOSStatusErrorDomain Code=-12101 "(null)"}}, null, null, null)

Example code (optional)

getStorageOrderedVideosAssets() async {
    //dynamicAlbumDetailAssets.clear();
    storageVideos.addAll(videos);
    await _populateVideoSizes();
  }

  Future<void> _populateVideoSizes() async {
    List<AssetEntity> problematicEntities = [];

    for (var entity in dynamicAlbumDetailAssets) {
      try {
        await _processEntity(entity);
      } catch (e) {
        debugPrint("######## Error accessing file for entity $entity: $e");
        problematicEntities.add(entity);
      }
    }

    // Retry problematic entities
    for (var entity in problematicEntities) {
      try {
        await _processEntity(entity);
        problematicEntities.remove(entity); // Remove if successful on retry
      } catch (e) {
        debugPrint("######## Retried and still error for entity $entity: $e");
      }
    }

    // Sort the successfully processed entities
    dynamicAlbumDetailAssets.sort((a, b) {
      int sizeA = videoSizes[a] ?? 0;
      int sizeB = videoSizes[b] ?? 0;
      return sizeB.compareTo(sizeA); // Sort by size in descending order
    });

    // Append problematic entities at the end
    dynamicAlbumDetailAssets.addAll(problematicEntities);
  }

  Future<void> _processEntity(AssetEntity entity) async {
    final file = await entity.file;
    final size = file?.lengthSync() ?? 0;
    videoSizes[entity] = size;
  }

Contact

omermustekiin@gmail.com

AlexV525 commented 1 week ago

Could you upgrade to the latest version and dump the exact stack trace if it is still reproducible?