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

File missing in the path from PlatformFile #194

Open
OlehSalamakha opened this issue Feb 7, 2025 · 1 comment
Open

File missing in the path from PlatformFile #194

OlehSalamakha opened this issue Feb 7, 2025 · 1 comment

Comments

@OlehSalamakha
Copy link

Here is my scenario.
Open File Picker -> Select File -> receive platform file -> call platform specific func on Android to check if file exists:

 val launcher = rememberFilePickerLauncher(mode = PickerMode.Single, type = PickerType.Image) { file ->
    checkIfFileExists(file?.path)
}


fun checkIfFileExists(path: String?) {

val file = File(path)
println(file.exists())
}

Path from platform file looks like this /data/user/0/my_package/files/1000015890.jpg.

@vinceglb
Copy link
Owner

vinceglb commented Feb 7, 2025

Hi @OlehSalamakha! Thanks for creating this issue.

This is the expected behavior. Android file picker returns a Uri. It means that it is not directly convertible to java.io.File. Also, this Uri is only usable during the current user session. After the user closes his app, this Uri will be invalidated.

See more here: https://developer.android.com/training/data-storage/shared/documents-files#persist-permissions

If you want more control over your file, you can copy it into the internal app storage. This time, it will be a java.io.File, and you'll have full access to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants