Giter Club home page Giter Club logo

Comments (20)

kinex avatar kinex commented on August 18, 2024

Hi, That is not possible unless you set OpenFileDialogParams.copyFileToCacheDir to true. Picked file may locate e.g. on Google Drive or on other storage provider so "absolute path" is not available. If you have different information please reopen with more details.

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

It seem that the absolute_path plugin can retrieve this information

from flutter_file_dialog.

kinex avatar kinex commented on August 18, 2024

It seems to copy the file to a cache dir at least in some cases. What is your use case, why do you need this?

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

We are working on elrepo.io, this is related to #12 .

The use case is we share on our "F2F backend" a file: the user select a file, and this filepath is passed to our backend to share it over the f2f network. This backend, called RetroShare, don't understand Android Uri scheme, so we have to pass the absolute file path.

We don't want to create a cached file to do not waste phone space, we want to access directly to the file.

from flutter_file_dialog.

kinex avatar kinex commented on August 18, 2024

Have you tried using that other plugin, does it give you the path you need?

If user picks a file e.g. from Google Drive, is the file physically present on user's device yet? If not, you cannot have an absolute path to it? Or are you expecting to get a file URL pointing to the file at Google Drive?

And even if you have an absolute path to a file located on user's device, have you tested that you can access the file in Android using the absolute file path? I think there might be some OS restrictions which prevent you from accessing the file with an absolute path (especially in the latest Android versions).

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

Hi,

We need the local path, what mean that we only want to pick local files. If we create params like:

final params = fileDialog.OpenFileDialogParams(
                    localOnly: true,
                    copyFileToCacheDir: false
                  );

The localOnly option is supposed to return local files only right? So we can have the absolute path from them, isn't it?

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

As commented here, the plugin flutter_absolute_path: ^1.0.6 makes our app crash without error message.

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

Hi,

Just to know, the option localOnly: true should return only local files (not those on the cloud)?

Thanks

from flutter_file_dialog.

kinex avatar kinex commented on August 18, 2024

Yes it should return local files only.

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

So setting localOnly: true with copyFileToCacheDir: false could return the absolute path. Are you going to support this? Otherwise I have to find another way to retrieve the absolute path.

Thanks in advance!

from flutter_file_dialog.

kinex avatar kinex commented on August 18, 2024

So what do you do with the absolute path? Do you want to for example read the file? Have you tested that reading a file with an absolute path is possible or does Android security features prevent it?

It could be supported if the absolute path is really useful, but only in that case. But I have not investigated is it possible to get the absolute path and how is it done. I am quite busy so I recommend a PR if possible.

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

So what do you do with the absolute path?

Read the file from the file system to share it in our app. As is an application to share content, we don't want to create a copy on the file system because the devices have a limited storage.

Have you tested that reading a file with an absolute path is possible or does Android security features prevent it?

On Android 10/Q if you add y the following lines you can read the file from the storage:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
   <application
        android:requestLegacyExternalStorage="true"
    >

What do you think if I write a PR where, if localOnly: true and copyFileToCacheDir: false return the absolute path?

from flutter_file_dialog.

kinex avatar kinex commented on August 18, 2024

Thanks for the details. Then it makes sense. Please write a PR.

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

Hi,

Get absolute filepath on Android / AndroidX is not trivial.

We can add this code to the app.

But I don't know why, I can't let it work inside this plugin. Maybe you can ask me something:

The parameter this.context passed here, in the FlutterAbsolutePathPlugin, is the same kind of context that the passed here, in the flutter_file_dialog plugin (this).

From FlutterAbsolutePathPlugin is the context passed to the plugin when instantiated.

From flutter_file_dialog is of type Activity, declared here.

As we need the context to get the absolute file path maybe this "context type" matter, because I get an error when used here.

I-m not Android developer and I'm not sure about the difference.

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

For some reason when I'm trying to adapt the code of FlutterAbsolutePathPlugin, at the time it call the cursor to get the absolute path, it doesn't work on the flutter_file_dialog.

On the line linked above, you will see the instantiation of the cursor, witch return, for the same hardcoded URI, in the FlutterAbsolutePathPlugin:

context type equals to io.flutter.app.FlutterApplication
cursor!!.moveToFirst() is TRUE
cursor!!.getCount() is 1

Instead, the same kotlin class, imported on the flutter_file_dialog, witch we send the same context as marked here, return:

context type equals to android.app.Application
cursor!!.moveToFirst() is FALSE
cursor!!.getCount() is 0

So I suppose that the problem is how the context instantiate the cursor, maybe we are not using the correct context.

If you have any ideas of how to fix this, I could write the code. BTW I'm going to combine the two plugins

from flutter_file_dialog.

kinex avatar kinex commented on August 18, 2024

I don't have quickly any ideas what is wrong. Please read the Flutter docs for implementing a Flutter plugin if not read yet.

Actually this looks too much like a hack to be included in this plugin after all, so I suggest you implement a separate plugin for this. I can try to help you there if needed. Can you take an URL from this plugin and convert it to an absolute path using the other plugin?

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

Hi,

I created a fork trying to integrate both plugins. Take a look that I hardcoded the uri path here:

https://github.com/selankon/flutter_file_dialog/blob/return-noncached-absolute-filepath/android/src/main/kotlin/com/kineapps/flutter_file_dialog/FlutterFileDialogPlugin.kt#L149

Also if you want take a look at this comment to see where I am:

https://gitlab.com/elRepo.io/elRepo.io-android/-/issues/40#note_620591573

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

I opened a stackoverflow question

https://stackoverflow.com/questions/68302885/android-cursor-dont-work-on-a-flutter-plugin-with-android-embedding-v2

from flutter_file_dialog.

selankon avatar selankon commented on August 18, 2024

After clean the code and migrate it properly to Android embedding V2, I let absolute file path plugin working.

I suggest to combine the two plugins to get the absolute path.

BTW, I think the problem merging the two plugins was something related of how this plugin get the activity context. If needed, we can try to merge it on the future, but for the moment, getting absolute path from here is not needed.

Those who need the absolute path, try this PR of the flutter absolute path plugin where I accomplish it with AndroidX and Flutter embedding V2.

KasemJaffer/flutter_absolute_path#15

Thanks for the attention

from flutter_file_dialog.

kinex avatar kinex commented on August 18, 2024

Great to hear you found a fix! I could take a closer look at your code when I have time. If it doesn't add too much complexity to this plugin, merging the code here could make sense.

from flutter_file_dialog.

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.