Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 2 Support (Qt 5) › FileDialog: get file path to read file from files like "content://…"

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #24371

    Volker

    Hi,

    I use FileDialog to upload file on server and on Android file looks like “content://com.android.providers.media.documents/document/image%3A133” if I select an image. Is there an easy way to convert it to real file path in order to open file in C++ code?

    Regards

    Roman

    #24373

    Alex
    Felgo Team

    Hi Volker,

    are you referring to the Qt.labs FileDialog? https://doc.qt.io/qt-5/qml-qt-labs-platform-filedialog.html

    The problem is that on Android this Qt component does not fully support all cases, and required persistance handling to re-access the file after fetching it using the dialog. This is also partly covered in this thread: https://forum.qt.io/topic/113328/how-to-convert-android-content-url-and-use-it-to-open-file

    If this is only about images, did you try using the image picker method from the Felgo NativeUtils instead? https://felgo.com/doc/apps-howto-display-images-and-photos/#selecting-a-photo-from-the-gallery

    Best,
    Alex

    #24379

    Volker

    Hi Alex,

    yes, I’m using FileDialog and saw this post, but found suggested solutions too complicated for such simple case and I hoped Felgo has something that provide simple solution for this. Unfortunately I need the possibility to attach any file for transmission like mail application does it with attachments…

    #24380

    Alex
    Felgo Team

    Hi Volker,

    I would suggest to also ask this in the Qt forums directly, maybe there is another trick to it. We do not have a custom file picker for any file type on top of the Qt components at the moment.

    Best,
    Alex

    #24386

    Volker

    Hi Alex,

    starting from Qt 5.13 and beyond QFile can resolve/open content:// like URI on android:

    https://www.volkerkrause.eu/2019/02/16/qt-open-files-on-android.html

    I can read file selected with File Dialog and upload content. But the file name in “content://” is something like “msf%3A150” and not real file name (something.pdf in my example).  I found some possible solution via JNI call here

    https://forum.qt.io/topic/116079/cant-get-the-correct-filepath-from-filedialog-in-android/6

    but still wander why QFile cannot give me real file name if I have access to its content anyway…

    #24539

    nks (baumemo)

    Is there an out of the box solution planned in Felgo?

    #24543

    Alex
    Felgo Team

    Hi,

    the Android file system by default is designed to give you single-use access to a file. Thus the FileDialog will request the file, and pass the content URI for temporary use. If you would like to get “permanent access”, the best thing is to store a copy of this file to the application data (e.g. using FileUtils). There are other ways with content resolvers to get permanent access to the file, but this is not being used by the Qt implentation of the FileDialog.

    We will have a look if we can provide some helper here to make it easier to access the file type.

    Best,
    Alex

    #24546

    nks (baumemo)

    Hi Alex,

    thank you very much :).

    Regards.

Viewing 8 posts - 1 through 8 (of 8 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded