Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathAccessException when saving file do firectory from FilePicker.platform.getDirectoryPath #1696

Open
1 of 4 tasks
mateusz-bak opened this issue Feb 2, 2025 · 2 comments
Labels
new issue An issue that hasn't yet been seen from the maintainer stale

Comments

@mateusz-bak
Copy link

Describe the bug
When I select a directory other than Documents and try to save the file I get

PathAccessException: Cannot open file, path = '/storage/emulated/0/Openreads/Openreads-2025_2_2-16_51_38.backup' (OS Error: Operation not permitted, errno = 1)

Platform

  • Android
  • iOS
  • Web
  • Desktop

Platform OS version
Emulator, Android 15,
OnePlus 8T, Android 14

How are you picking?

        String? selectedDirectory =
            await FilePicker.platform.getDirectoryPath();

        File('$selectedDirectory/$fileName').writeAsBytesSync(
          File(tmpBackupPath).readAsBytesSync(),
        );

Details to reproduce the issue
As in the code, open directory picker and try to save the file there.

Error Log

PathAccessException: Cannot open file, path = '/storage/emulated/0/Openreads/Openreads-2025_2_2-16_51_38.backup' (OS Error: Operation not permitted, errno = 1)

Flutter Version details

flutter doctor -v
[✓] Flutter (Channel stable, 3.27.3, on Fedora Linux 41 (Workstation Edition) 6.12.10-200.fc41.x86_64, locale pl_PL.UTF-8)
    • Flutter version 3.27.3 on channel stable at /home/mateusz/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (12 dni temu), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    • Android SDK at /home/mateusz/Android/Sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: /home/mateusz/.local/share/JetBrains/Toolbox/apps/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 19.1.7 (Fedora 19.1.7-1.fc41)
    • cmake version 3.30.5
    • ninja version 1.12.1
    • pkg-config version 2.3.0

[✓] Android Studio (version 2024.2)
    • Android Studio at /home/mateusz/.local/share/JetBrains/Toolbox/apps/android-studio
    • 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
    • android-studio-dir = /home/mateusz/.local/share/JetBrains/Toolbox/apps/android-studio
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)

[✓] VS Code (version 1.96.4)
    • VS Code at /usr/share/code
    • Flutter extension version 3.102.0

[✓] Connected device (2 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 15 (API 35) (emulator)
    • Linux (desktop)              • linux         • linux-x64   • Fedora Linux 41 (Workstation Edition) 6.12.10-200.fc41.x86_64

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

! Doctor found issues in 1 category.

Additional context
My Manifest:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Also it worked with package shared_storage with below code but it is now discontinued.:

        final selectedUriDir = await openDocumentTree();
        if (selectedUriDir == null) {
          return;
        }
        createFileAsBytes(
          selectedUriDir,
          mimeType: '',
          displayName: fileName,
          bytes: File(tmpBackupPath).readAsBytesSync(),
        );
@mateusz-bak mateusz-bak added the new issue An issue that hasn't yet been seen from the maintainer label Feb 2, 2025
@devtronic
Copy link

I'm facing the same issue. I'm using the flutter_file_dialog package as a work around. When this problem is solved I'll switch to this package.

Copy link

github-actions bot commented Mar 9, 2025

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new issue An issue that hasn't yet been seen from the maintainer stale
Projects
None yet
Development

No branches or pull requests

2 participants