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

Feature request: add an option parameter to return the original path and avoid caching the file (for Android/iOS). #1498

Closed
twinkles-twinstar opened this issue Apr 22, 2024 · 2 comments
Labels
stale suggestion New feature or request

Comments

@twinkles-twinstar
Copy link
Contributor

The original file path is useful sometimes, for example:

  • Reading raw files directly without caching the files can improve application performance.
  • The application may need to write data to the original file, and the developer hopes that modifications can be directly applied to the original file.
  • The path itself has certain information, and developers need it.

I've read the wiki and I know why file_picker doesn't return the original path, but even in higher versions of Android/iOS platforms, getting the absolute path is still possible:

  • iOS: UIDocumentPickerViewController init(forOpeningContentTypes: [UTType]) returns the URL file://path/to/original containing the original path.

    Apps have permission to read or write files in the Files.app picker dialog, which are shared files exposed by other apps through LSSupportsOpeningDocumentsInPlace UIFileSharingEnabled.

    I haven't tried it in swift or dart, but the C/C++ filesystem API is able to manipulate these original paths normally, including reading, writing, creating or deleting directories.

  • Android: It seems that it is impossible to obtain the original path on the Android platform, because DocumentsUI returns a Content URI, but developers may analyze the absolute path from the Content URI. For example:

    • content://com.android.externalstorage.documents/document/primary:<file-path> returned by DocumentsUI, the absolute path can be obtained through simple string concatenation <primary-storage-path>/<file -path>, for example /storage/emulated/0/Music/abcd.mp3.

    • content://me.zhanghai.android.files.file_provider/file://<file-path> returned by Material Files, an open source file manager app, the path component in the URI it returns contains The file URL which is the absolute path of the file. The Content URI returned by many third-party file manager apps will contain the absolute path of the file.

    Although not all Content URIs can parse to absolute paths, it is still possible to obtain absolute paths. file_picker can return the Content URI to the user, and it is the user's responsibility to try to parse the URI in Dart.

To sum up, I hope that file_picker can add a new option parameter dontCache/justCacheInNeeded and a new method cacheFileOfUriOnAndroid to affect the behavior of the plug-in on the following platforms:

  • iOS: Return absolute path.

  • Android: Return Content URI and let the user analyze the URI in Dart. If the URI does not contain an absolute path, the user calls cacheFileByUriOnAndroid again to create the cache.

Below are the picker implementations used in my app, they behave as described above, they work well, but they are very simple and don't have the rich functionality of file_picker , just for reference:

@twinkles-twinstar twinkles-twinstar added the suggestion New feature or request label Apr 22, 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 Apr 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
stale suggestion New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant