Comments (7)
That is great! It is everything you need to create this feature. But the decision is up to you, if you want it. I don't have right now the possibility to test it and make a pull request.
from flutter_file_picker.
You can’t remove the permission to write files because if somebody wants to actually modify a remote file (such as files in google drive) you need them to first be cached. You can’t open a file descriptor for a URI of a remote file.
from flutter_file_picker.
This is the whole idea of openable content.
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
You don't have to have access to all the files if you want only the content of the file picked by the user. The user gives you explicit permission to this one file.
Extracting the path from content:/ uri is just the trick. And it is the wrong way to do it. It won't always work.
By starting the intent you are only guaranteed that you will have access to the file by calling:
getContentResolver().openInputStream(uri)
And this access is only temporarily. You should create your own copy.
How Google Drive work:
- user picks the file from Drive
- Drive downloads the file to its private directory (this file is temporary),
- Drive creates the URI to the file, the file is temporarly available through FileProvider of the Google Drive
- here you can/should make your own copy. You can do it to your private external storage. Since KitKat you don't need any permission to do it.
Android:
sourceUri = choosenFile();
inputStream = getContentResolver().openInputStream(sourceUri);
fileName = extractFileName(sourceUri);
writeToFile(inputStream, destinationDirectory, fileName);
Dart:
/// destinationDirectory is a path to the directory where the app has write permission
String getPath(..., {String destinationDirectory});
from flutter_file_picker.
I’m aware of that approach. However for
API > 15 & < 21 you still need to ask for permissions.
The problem with that, is if the user wants to extract the absolute path of the file, let’s say, to save some other files in that directory, I’m not sure if that will be possible using the content resolver.
Edit: also, as it is, you don’t actually need to call any plugin method to write the file into. You can use it from the Dart File
directly.
How what would happen, for an instance, in your provided example, if the user don’t give a destinationPath? Would you just use the default temp directory directly?
from flutter_file_picker.
API > 15 & < KitKat you still need to ask for permissions.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
How what would happen, for an instance, in your provided example, if the user don’t give a destinationPath? Would you just use the default temp directory directly?
Or if the user doesn't provide destinationPath, you can just call getPath() in the old way.
But the getPath() is always a path to a file that should be treated as temporary. The FileProvider can remove it at any time.
You should be aware that URI could be something like this: content://com.google.drive/files/document.pdf
You won't ever have access to this file. You can only get it through getContentResolver()
Dart:
// here the user will need WRITE permission
getPath(...); // without destinationDirectory
// here the user doesn't need WRITE permission
getPath(..., destinationDirectory: myPath);
from flutter_file_picker.
You should be aware that URI could be something like this: content://com.google.drive/files/document.pdf
You won't ever have access to this file. You >can only get it through getContentResolver()
This is something that is already being made somehow. Check the android FileUtils.java
source.
from flutter_file_picker.
This has been already done in 1.3.6
. Thank you.
from flutter_file_picker.
Related Issues (20)
- Issue: Unable to Read File Content (CSV) HOT 1
- [iOS] File picker crashes when accidentally picking a file across async gap HOT 6
- Retorna um valor após várias tentativas de seleção HOT 3
- We are using Android activity launch mode as singleInstance. Few of the devices file selection not returning values.Its giving null. We can't change the launch mode as well becuase other features may break.Please check this critical bug.Lots of users are reporting this HOT 7
- I think that not work in web HOT 5
- BUG: Picking a folder in iOS causes the original folder to be deleted. HOT 7
- Pick a video but it’s treating them like image HOT 6
- in isolate read a large(17mb) txt file with Error: FileSystemException: File closed HOT 3
- [Linux] FilePicker.platform.pickFiles() always return null HOT 5
- [Windows] The picker is pausing the ripple effect on buttons HOT 2
- Don't automatically close the file window after selecting a file. HOT 2
- iOS privacy manifest required HOT 6
- Is it possible to add support for preventing too many files to be picked? HOT 4
- path null HOT 16
- Permission Error in Android Version 13. HOT 14
- Unable to pick some files(specifically pdf) in android 13 HOT 3
- dyld: Library not loaded: @rpath/DKImagePickerController.framework/DKImagePickerController HOT 3
- Persistent file access option HOT 4
- File_picker doesn't behave as expected on Android 14 HOT 4
- Apple's update to their API policy - Required Reason HOT 2
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 flutter_file_picker.