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

Path string returned by saveFile() on Android does not resolve to the actual selected file path #1590

Closed
1 of 4 tasks
lumpsoid opened this issue Sep 4, 2024 · 7 comments
Closed
1 of 4 tasks
Labels
new issue An issue that hasn't yet been seen from the maintainer stale

Comments

@lumpsoid
Copy link

lumpsoid commented Sep 4, 2024

Before creating an issue, make sure that you are on the latest file_picker version and that there aren't already any similar opened inssues. Also, check if it isn't described on the Wiki, specially on Troubleshooting page.

Also, sometimes a simple flutter clean and flutter build again with latest file_picker version, may end up by fixing cached issues, so I encourage you to first do so.

Describe the bug
This is reopening of the #1553, because bot closed it, but nobody looked into it.

When using the saveFile() method of the file picker, the returned string path is different from the actual picked file location. It will always be inside the Download folder.

Platform

  • Android
  • iOS
  • Web
  • Desktop

Platform OS version
14 (API 34)

How are you picking?

final now = DateTime.now();
final timeStamp = '${now.year}-${now.month}-${now.day}';
final fileName = 'export_$timeStamp.csv';
String? filePath = await FilePicker.platform.saveFile(
  dialogTitle: 'Select a folder to export data',
  fileName: fileName,
  initialDirectory: 'Download',
  bytes: Uint8List(
      0), //https://github.com/miguelpruivo/flutter_file_picker/issues/1523
);
if (filePath == null) return;
debugPrint(filePath);

Details to reproduce the issue
Provide all the details to reproduce the issue.

Flutter Version details

[✓] Flutter (Channel stable, 3.22.2, on NixOS 24.11 (Vicuna) 6.6.45, locale en_US.UTF-8)
    • Flutter version 3.22.2 on channel stable at /nix/store/a62pd11p4cywpm0rh0i092s10dx1wm6m-flutter-wrapped-3.22.2-sdk-links
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision nixpkgs000 (), 1970-01-01 00:00:00
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /nix/store/jnh87nqcvdnda2dvw6qj6rcah1mhqpd4-android-sdk-env/share/android-sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /nix/store/jnh87nqcvdnda2dvw6qj6rcah1mhqpd4-android-sdk-env/share/android-sdk
    • ANDROID_SDK_ROOT = /nix/store/jnh87nqcvdnda2dvw6qj6rcah1mhqpd4-android-sdk-env/share/android-sdk
    • Java binary at: /nix/store/zv325ff26ahbywl59q8cj9vm63sisna6-openjdk-17.0.11+9/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+9-nixos)
    • 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 18.1.8
    • cmake version 3.29.6
    • ninja version 1.12.1
    • pkg-config version 0.29.2

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

[✓] Connected device (2 available)
    • RMX2156L1 (mobile) • AAJJDMCMGEQOEIDE • android-arm64 • Android 14 (API 34)
    • Linux (desktop)    • linux            • linux-x64     • NixOS 24.11 (Vicuna) 6.6.45

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

Additional context
The android implementation of saveFile uses Environment.DIRECTORY_DOWNLOADS, so safeFile will always return the path to the downloads directory.

String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.getAbsolutePath() + File.separator + FileUtils.getFileName(uri, this.activity);

if nobody knows for now, how to resolve this issue, then as a hack, is it possible to use saveFile method without dialog?

@lumpsoid lumpsoid added the new issue An issue that hasn't yet been seen from the maintainer label Sep 4, 2024
@deathblade666
Copy link

deathblade666 commented Sep 4, 2024

I'd be curious if they couldn't just modify the file pick function since assumably it has to get the full path to the file to be able to either A) copy it to memory B) read the contents to memory or C) action on it? Saving is effectively the same just instead of returning just the full path you can manually set a file name, which that part works fine. Honestly even if actually saving the file doesn't work, i would think in most cases so long as you have the path+filename you should be able to write to it via other means

@lumpsoid
Copy link
Author

lumpsoid commented Sep 8, 2024

@deathblade666
it would be strange, because we can save data to the specified path, if used with bytes parameter, or is it like separate thing while you in dialog? and you can't just transfer this information back into the dart vm?

but probably there is some platform specific shenanigans

@deathblade666
Copy link

@deathblade666

it would be strange, because we can save data to the specified path, if used with bytes parameter, or is it like separate thing while you in dialog? and you can't just transfer this information back into the dart vm?

but probably there is some platform specific shenanigans

No stranger than if you were to pick a file, you'd just have to add additional actions to do what you want with it (dart io should be able to handle any file system actions provided a correct path).

Though, the primary issue here is that the returned path is incorrect, however the return path when picking a file (pickFiles()) is correct, so my thought is why not use the same logic for both. Since outside the bytes flag they are effectively doing the same thing, just one offers a "save as" dialog instead of a select file dialog.

Copy link

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

@github-actions github-actions bot added the stale label Sep 16, 2024
@lumpsoid
Copy link
Author

issue still actual and there were no changes

after
flutter pub upgrade
and
flutter run
test app for this issue is still returning wrong picked path.

@github-actions github-actions bot removed the stale label Sep 23, 2024
Copy link

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

@github-actions github-actions bot added the stale label Sep 30, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

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