miguelpruivo / flutter_file_picker

File picker plugin for Flutter, compatible with mobile (iOS & Android), Web, Desktop (Mac, Linux, Windows) platforms with Flutter Go support.
MIT License
1.35k stars 676 forks source link

Filetype.audio always return path /item.mp3 and failed to read with IOSink. #441

Closed afandiyusuf closed 4 years ago

afandiyusuf commented 4 years ago

file_picker: ^2.0.7

Describe the bug All music files that picked with this package always returning path /item.mp3 and flutters IOSink failed to read that path.

Issue details

  1. Platform OS version (iPhone 8 simulator IOS 14, real device iPhone 7s Ios version 14.0.1).

Error Log

[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: Unhandled error FileSystemException: Cannot open file, path = '/item.mp3' (OS Error: No such file or directory, errno = 2) occurred in Instance of 'MeditationAudioBloc'.

Flutter Version details flutter doctor -v

[✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.15.6 19G73, locale en-ID)
    • Flutter version 1.22.0 at /Library/flutter
    • Framework revision d408d302e2 (13 days ago), 2020-09-29 11:49:17 -0700
    • Engine revision 5babba6c4d
    • Dart version 2.10.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/yusufafandi/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • ANDROID_HOME = /Users/yusufafandi/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/yusufafandi/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.9.3

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (1 available)
    • iPhone yusuf (mobile) • b767941ad75b18ab00571194a8e16ed6ef69061c • ios • iOS 14.0.1

• No issues found!

Additional context This is my code

FilePickerResult result =
        await FilePicker.platform.pickFiles(type: FileType.audio);
    if (result != null) {
      print("PATH IS");
      print(result.files.single.path);
      setState(() {
        currentFileName = result.files.single.name;
        currentFilePath = result.files.single.path;
      });
      _gotoInputDataAfterUploadFile(context);
      Navigator.of(context).pop();
    } else {
      Navigator.of(context).pop();
      return;
    }
miguelpruivo commented 4 years ago

@afandiyusuf what are the type of files that your are picking? Are DRM protected files from Music app?

afandiyusuf commented 4 years ago

@miguelpruivo I think not, just some random mp3 file, I send it from my mac via Itunes. I tried different mp3 filename, and the path still returning /item.mp3.

miguelpruivo commented 4 years ago

@afandiyusuf fixed with 2.0.11. 🚀

Previous to the update, it was impossible for security reasons to directly access ipod-library files (even those non DRM protected). From now on, those files will be exported (to m4a extension which is similar to mp3 and natively efficient by iOS) and cached into the /tmp directory so you can use within your app. Have in mind that if you want to keep those files permanently in your app's content, you should copy/move it to your app's documents folder.

Let me know if you have any other issue related to this. If so, feel free to reopen it.

Thank you!

afandiyusuf commented 4 years ago

Great, will try it for my current project. Thank you very much @miguelpruivo

muarachmann commented 3 years ago

Hi @miguelpruivo First a big thanks for the wonderful job done here.

I am having the same issue (picking audio files on IOS) It opens the music app and I can see the path of the m4a files. However I can't read them as it throws the Unhandled error FileSystemException: I however don't know where the cached files are being stored to move it to my applications root dir or so.

Any help would be greatly appreciated thanks.

miguelpruivo commented 3 years ago

@muarachmann what is the FileSystemException being thrown?

muarachmann commented 3 years ago

@muarachmann what is the FileSystemException being thrown?

@miguelpruivo I get this for example - FileSystemException: Cannot open file, path = '/private/var/mobile/Containers/Data/Application/4A493D0B-E030-4900-AD5C-456FB0BBE7EC/tmp/oceans.m4a' (OS Error: No such file or directory, errno = 2)

miguelpruivo commented 3 years ago

Probably the file is being purged somehow. Can you try accessing the file immediately after picking it?

muarachmann commented 3 years ago

@miguelpruivo not working, keeps giving me that error, and this fails with my audioplayer as I can't read the file. Doing a try and catch, I noticed the file never existed. Let me know if you need any other info

muarachmann commented 3 years ago

However, the results returned by FilePickerResult after this

  FilePickerResult result =
    await FilePicker.platform.pickFiles(type: FileType.audio, allowMultiple: true);

seems to be ok, I get a List of paths as thus

[/private/var/mobile/Containers/Data/Application/4A493D0B-E030-4900-AD5C-456FB0BBE7EC/tmp/oceans.m4a, /private/var/mobile/Containers/Data/Application/4A493D0B-E030-4900-AD5C-456FB0BBE7EC/tmp/test1.m4a, /private/var/mobile/Containers/Data/Application/4A493D0B-E030-4900-AD5C-456FB0BBE7EC/tmp/test2.m4a]
muarachmann commented 3 years ago

Hi @miguelpruivo more logs on Xcode, maybe this has to do with Apple,

[iTunesCloud] ACAccountStore 0x280337720 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"
2020-12-16 13:07:10.902152+0100 Runner[534:64078] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""

Any idea on this?