Comments (3)
I also didn't realize that there is a Copy As
with the document APIs on iOS, I thought it would be editable in place.. good to know.
Regarding flags: I think this is pretty similar to persistable
- how about reusing it? it's basically the same thing? (It can only be read, and not written back.. and when we implement the proposed fix, we'd delete the file from the Inbox
, it is also no longer readable)
I would guess from the name Inbox
that we could also delete all of the files, because there shouldn't be any retained files anyway, those are only files which are copied there so they can be imported by the app. But I agree, it would be safer to only delete files we explicitly pass on..
To be honest, I think the file handling is generally a bit wrong right now with many left-over files by default.. Every operation should take a callback within which the caller on the dart side has access to the file, and once the callback returns, the file is always deleted. So for example:
final result = await FilePickerWritable().readFileWithIdentifier(fileIdentifier, (fileInfo, file) async {
// now we can access `file`
final contents = await file.readAsString();
return contents;
});
// now `file` is deleted again.
because the FileInfo.file
right now should actually only be read from.. because it is just a copy in most cases (e.g. android content uris, ios urls). but nobody is deleting those files.
I could imagine a similar write operation which takes care of creating a temporary file the caller can use to persist changes..
await FilePickerWritable().writeFileWithIdentifier(fileIdentifier, (file) async {
// now we can access `file`
await file.writeString('lorem ipsum);
});
// now `file` is deleted again.
ie. the FileInfo would actually no longer have the file
property, but it is only available while inside the callback..
from file_picker_writable.
Regarding flags: I think this is pretty similar to
persistable
- how about reusing it? it's basically the same thing? (It can only be read, and not written back.. and when we implement the proposed fix, we'd delete the file from theInbox
, it is also no longer readable)
If you're OK with this solution, I do think it's best. I was assuming that because the identifier is technically persistable (it just points to the "wrong" file) that you would prefer persistable: true
. But that does violate the spirit and main use case of the plugin.
Actually it turns out you can't write to files in Documents/Inbox
, so treating them as non-persistable seems like very much the right choice.
To be honest, I think the file handling is generally a bit wrong right now with many left-over files by default
You are properly using NSTemporaryDirectory
to get tmp/
; according to the docs:
Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.
The contents of this directory are not backed up by iTunes or iCloud.
Since the OS will clean it up I think it's OK to leave them there. Also the user can delete FileInfo.file
from Dart if they really want to.
It's just files in Inbox
that need additional handling, and I think it's unreasonable to do so from the Dart side.
Every operation should take a callback within which the caller on the dart side has access to the file, and once the callback returns, the file is always deleted
ie. the FileInfo would actually no longer have the
file
property, but it is only available while inside the callback.
I understand and agree with your desire here, but I have to caution against this kind of API:
-
I don't think it's feasible to actually control the lifetime of the
file
: You can't prevent someone from grabbing it and retaining it within the callback, or adding it to a Stream (in fact one can recreate the oldFuture
-based API fairly easily by doing so). Callbacks may help communicate your intent, but they are also quite painful to work with. -
You can achieve the same delete-on-return semantics with the current API: when the Dart-side
MethodChannel
call handler returns, the result is fed back to the platform-side. You can delete the file there if you really want.
I will update my PR with:
persistent: false
for Copy-to files- Deleting
Inbox
files after return from Dart
from file_picker_writable.
This was addressed by #3
from file_picker_writable.
Related Issues (20)
- Running on physical iphone, "The file couldn’t be opened because it doesn’t exist." HOT 6
- Unhandled exception when reading file on Android HOT 3
- Errors opening from intent/open-in/copy-to are swallowed HOT 5
- Android: Fallback for unsupported OPEN_DOCUMENT intent
- path_provider <2.0.0 restriction causing problems HOT 6
- Remove android.permission.READ_EXTERNAL_STORAGE HOT 4
- Persistable access to a directory HOT 8
- Incompatible with other intent handling plugins
- writeFileWithIdentifier method doesn't work properly on Android 10 HOT 9
- Cannot select files, they seemed to be disabled
- How to get the chosen file path on createFile HOT 1
- Not working on Android when the activity is forcibly restarted by the Android system HOT 7
- Implement a feature that covers usescases like limiting to "text/plain" HOT 1
- Won't build for Android with Flutter 3.0 HOT 1
- How can I get intent url by this package? HOT 1
- Don't limit file name length to 30 letters HOT 1
- Interfering with Share extension plugin on iOS
- Android Gradle Plugin 8.0 compatibility
- [IOS] skipDestinationStartAccess warning
- Add macOS support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from file_picker_writable.