Closed devfemibadmus closed 5 months ago
@stuartmorgan
As I said in the referenced issue, this is likely a wontfix, since:
it's not at all clear how many of the APIs in File would work. content URIs aren't files, they are their own distinct concept; that's why they have a different scheme in the first place.
As to this:
The conclusion of the #25659 is to use a plugin https://pub.dev/packages/flutter_absolute_path which i dont think that will be Good bcus this plugin copy the files temporary to another location
That was not "the conclusion" it was a suggestion from another user for one possible solution. There are better options that don't involve File
support, such as a plugin that specifically provide an interface for the kinds of things that can be done with content://
URIs, such as reading their data, without copying them, but also without suggesting that they can be, e.g., moved to a different path, which they can't.
For instance, there's been some discussion of reworking cross_file
to allow for arbitrary implementations, including content://
support.
Correct
such as a plugin that specifically provide an interface for the kinds of things that can be done with content:// URIs, such as reading their data, without copying them, but also without suggesting that they can be, e.g., moved to a different path, which they can't.
Good
there's been some discussion of reworking cross_file to allow for arbitrary implementations, including content:// support.`
inconclusion i should await the reworking ?
just that there are no better if these feature is not available
only ways are to render bytes
, file copy
, folder moved
My initial thought is that this doesn't belong in File
unless the API for accessing these URIs is identical to how files are accessed i.e. through open
, read
, etc. POSIX system calls.
From what @stuartmorgan wrote, that seems to not be the case - it uses the ContentProvider
API, right?
@brianquinlan nah doesn't use ContentProviderAPI its just like a normal path in android but instead of usual str /path/to/file its Uri instead
Uri uri = Uri.parse("file:///path/to/your/file");
File file = new File(uri.getPath());
You've shown a file:
URI, not a content:
URI. As I noted above, those have very different semantics.
@devfemibadmus In your example, does converting the content:
URI to a file path result in Image.file
working?
You've shown a
file:
URI, not acontent:
URI. As I noted above, those have very different semantics.
Thats just an example
@devfemibadmus In your example, does converting the
content:
URI to a file path result inImage.file
working?
nah, Oh yeah It's ContentProviderAPI
My initial thought is that this doesn't belong in
File
unless the API for accessing these URIs is identical to how files are accessed i.e. throughopen
,read
, etc. POSIX system calls.From what @stuartmorgan wrote, that seems to not be the case - it uses the
ContentProvider
API, right?
You're right it uses ContentProvider API, but still since its lead to a file destination, should be called through File
?
but still since its lead to a file destination
It doesn't though, it resolved via an interprocess system-meditated data transfer.
but still since its lead to a file destination
It doesn't though, it resolved via an interprocess system-meditated data transfer.
so what do we use? File?
@stuartmorgan @lrhn @brianquinlan
We should not use theFile
class for any URI scheme other than file:
.
The File
class represents a POSIX file, or its path really, which is why it can be converted to and from a File:
URI.
This is something else. It should be represented by something else.
If the problem is that some existing code accepts only File
objects, for a use whether a "content" object could also be accepted, then we may need to introduce a supertype for "readable resources".
(I'd consider introducing a new abstraction instead of using the platform File
class, because this sounds like something slightly different. A ReadableResource
with FileResource
and ContentResource
subtypes, perhaps.)
so what do we use? File?
I think that using File
is the wrong solution. This seems like an Android-specific problem that, as @stuartmorgan said, can be solved with a Flutter plugin.
I'm closing this issue because I think that it is out-of-scope for Dart. If you disagree, please reopen with your reasoning.
can be solved with a Flutter plugin.
and using FIle
is the way we can access that which is from Dart
, we have file
In Dart, there is a built-in class called File which represents a file on the filesystem.
final file = File(path);
// here path should be /Document/path/to/file/
nah, Oh yeah It's ContentProviderAPI
My initial thought is that this doesn't belong in
File
unless the API for accessing these URIs is identical to how files are accessed i.e. throughopen
,read
, etc. POSIX system calls. From what @stuartmorgan wrote, that seems to not be the case - it uses theContentProvider
API, right?You're right it uses ContentProvider API, but still since its lead to a file destination, should be called through
File
?
So if you say this should be solved with flutter plugin, i will like you to expatiate maybe i can do that
We should not use the
File
class for any URI scheme other thanfile:
.The
File
class represents a POSIX file, or its path really, which is why it can be converted to and from aFile:
URI.This is something else. It should be represented by something else.
If the problem is that some existing code accepts only
File
objects, for a use whether a "content" object could also be accepted, then we may need to introduce a supertype for "readable resources". (I'd consider introducing a new abstraction instead of using the platformFile
class, because this sounds like something slightly different. AReadableResource
withFileResource
andContentResource
subtypes, perhaps.)
YES! YES!! PLEASE!!!
Content Uri are now the standard way of accessing files in android. So, its frustrating that there is no direct support in Flutter/Dart for it. A third party plugin is not the best solution for this as it may or may not be maintained by the developer and may be buggy.
Content Uri are now the standard way of accessing files in android. So, its frustrating that there is no direct support in Flutter/Dart for it. A third party plugin is not the best solution for this as it may or may not be maintained by the developer and may be buggy.
finally someone is here for me
Content Uri are now the standard way of accessing files in android. So, its frustrating that there is no direct support in Flutter/Dart for it. A third party plugin is not the best solution for this as it may or may not be maintained by the developer and may be buggy.
finally someone is here for me
I believe you can reopen the request. This requirement is a must have feature.
I believe you can re-open the request. This requirement is a must have feature.
you cannot re-open your own issues if a repo collaborator closed them @brianquinlan @stuartmorgan @lrhn
Does sound like you want a ContentReader
API that accepts URIs and can read content through the corresponding Android API.
That's not the File
class.
It may not be a class that can even exist outside of Android.
Maybe the behavior is close enough to File
that it can pretend to implement File
. More likely, because the path
getter won't even work, it will be a separate API which can maybe work with file
URIs on all native platforms, and also with content
URIs on Android.
But it's not the File
class.
Not sure what it is, if not a complete implementation of ContentResolver
.
Damn.............this gonna be another limitation for flutter even thou its android?
I have opened a feature request on Flutter repository. https://github.com/flutter/flutter/issues/147037#issue-2252357646
we getting the features
@devfemibadmus
I am not sure we are getting them that soon, cross_file
would first need to be federated until some new features are merged, when this will be done (anybody can do this! If you feel you are capable, try to make it work and to get it merged), I'll probably do another proposal/PR once cross_file
will be federated. I did https://github.com/flutter/packages/pull/6625 mainly to get things moving with some code and ideas we can iterate on.
Use case
Request support for android
content:// uri
in the File class there is similar closed #25659. The conclusion of the #25659 is to use a plugin https://pub.dev/packages/flutter_absolute_path which i dont think that will be Good bcus this plugin copy the files temporary to another location then returns its absolute dir imagine working on large project where u work with many files, user will suffer for storage or sometimes not even enough storage to copy single fileand here #bug-flutter-fileimagevideo-not-working-with-android-action_open_document_tree-but-works-fine-in-kotlin
I convert the
content:// uri
to get stringabsolute path
but will end up in permission denied even thou permission been given successfully meaning converting doesn't work we can only access through content:// uri bcus we got that from https://developer.android.com/training/data-storage/shared/documents-filesthis issue is all derived from this simple flutter project https://github.com/devfemibadmus/whatsapp-status-saver
which we use https://developer.android.com/training/data-storage/shared/documents-files to get permission to folder, the code in android works fine bcus we can access content:// uri in adnroid but wont in flutter bcus
we can't access content:// uri in File
and with this, this simple flutter project is limited.Using manage_external_storage permission works fine but security issue app
reject from playstore
by the way not really recommended bcus of security please flutter request for feature Android support forcontent:// uri
in the File classProposal
Sample code
https://github.com/devfemibadmus/folderpermission
kotlin MainActivity.kt
Flutter main.dart