Code Monkey home page Code Monkey logo

Comments (7)

pjkroll avatar pjkroll commented on May 30, 2024 1

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.

miguelpruivo avatar miguelpruivo commented on May 30, 2024

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.

pjkroll avatar pjkroll commented on May 30, 2024

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.

miguelpruivo avatar miguelpruivo commented on May 30, 2024

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.

pjkroll avatar pjkroll commented on May 30, 2024

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.

miguelpruivo avatar miguelpruivo commented on May 30, 2024

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.

miguelpruivo avatar miguelpruivo commented on May 30, 2024

This has been already done in 1.3.6. Thank you.

from flutter_file_picker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.