Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Upload ios image with qt
Forum Updated to NodeBB v4.3 + New Features

Upload ios image with qt

Scheduled Pinned Locked Moved Mobile and Embedded
18 Posts 9 Posters 10.5k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zeecrowddev
    wrote on last edited by zeecrowddev
    #6

    Hello i've got the same problem :(
    Did you resolve it ?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vi67
      wrote on last edited by
      #7

      Hello,
      Same bug for me.

      There is no need to have a beautifull picture picker if we can't upload one of those pictures.

      One thing I don't understand :
      QML Image is able to understand a path like "file:assets-library:/asset/asset.JPG..."
      But neither QFile, nor QFileInfo, nor QImage can do that.
      Do you have an idea why ?

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vi67
        wrote on last edited by
        #8

        Guys, I found a solution :

        QString path("file:assets-library:/asset/asset.JPG...");
        QUrl url(path);
        path = url.toLocalFile();
        
        R 1 Reply Last reply
        1
        • V Vi67

          Guys, I found a solution :

          QString path("file:assets-library:/asset/asset.JPG...");
          QUrl url(path);
          path = url.toLocalFile();
          
          R Offline
          R Offline
          renatobibiano
          wrote on last edited by
          #9

          @Vi67 said:

          QString path("file:assets-library:/asset/asset.JPG...");
          QUrl url(path);
          path = url.toLocalFile();

          Thanks man, you saved me!

          ekkescornerE 1 Reply Last reply
          0
          • R renatobibiano

            @Vi67 said:

            QString path("file:assets-library:/asset/asset.JPG...");
            QUrl url(path);
            path = url.toLocalFile();

            Thanks man, you saved me!

            ekkescornerE Offline
            ekkescornerE Offline
            ekkescorner
            Qt Champions 2016
            wrote on last edited by
            #10

            @renatobibiano I tried:

            QString path("file:assets-library:/asset/"+fileInfo.fileName());
            QUrl url(path);
            path = url.toLocalFile();
            

            path then is

            "file:assets-library:/asset/asset.PNG?id=FB873B83-78E1-4B18-8601-0CD2CBD92308&ext=PNG"
            

            but url.toLocalFile() gives

            "assets-library:/asset/asset.PNG"
            

            so this doesnt work for me. any idea ?

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.9 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            ekkescornerE 1 Reply Last reply
            0
            • ekkescornerE ekkescorner

              @renatobibiano I tried:

              QString path("file:assets-library:/asset/"+fileInfo.fileName());
              QUrl url(path);
              path = url.toLocalFile();
              

              path then is

              "file:assets-library:/asset/asset.PNG?id=FB873B83-78E1-4B18-8601-0CD2CBD92308&ext=PNG"
              

              but url.toLocalFile() gives

              "assets-library:/asset/asset.PNG"
              

              so this doesnt work for me. any idea ?

              ekkescornerE Offline
              ekkescornerE Offline
              ekkescorner
              Qt Champions 2016
              wrote on last edited by ekkescorner
              #11

              found out HowTo get access to the Images on iOS.

              last entry of QStandardPath::PicturesLocation gives me access to

              assets-library://
              

              QDir entryInfoList() gives me QFileInfo and QFileInfo provides the filePath :

              "assets-library://asset/asset.PNG?id=E8CE839A-29EA-42B2-A8FD-89B57ABEC765&ext=PNG"
              

              QFileInfo() gets access to the Photos so of course also QFile can read them and so I can upload to REST service.
              was confused by the unusual pathes of Photos stored on iPhone.

              One missing point: I also want to use the Photos as source of QML Image.
              Normaly this is working to display an Image using filePath from QFileInfo:

                      Image {
                          id: theImage
                          anchors.fill: parent
                          source: Qt.resolvedUrl("file://"+currentFile.path)
                          fillMode: Image.PreserveAspectFit
                      }
              

              but for files from iOS assets-library I’m getting

              QML Image: Cannot open: file://assets-library//asset/asset.PNG
              

              any idea HowTo provide a correct URL to Image ?

              ekke ... Qt Champion 2016 | 2024 ... mobile business apps
              5.15 --> 6.9 https://t1p.de/ekkeChecklist
              QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

              kshegunovK 1 Reply Last reply
              0
              • ekkescornerE ekkescorner

                found out HowTo get access to the Images on iOS.

                last entry of QStandardPath::PicturesLocation gives me access to

                assets-library://
                

                QDir entryInfoList() gives me QFileInfo and QFileInfo provides the filePath :

                "assets-library://asset/asset.PNG?id=E8CE839A-29EA-42B2-A8FD-89B57ABEC765&ext=PNG"
                

                QFileInfo() gets access to the Photos so of course also QFile can read them and so I can upload to REST service.
                was confused by the unusual pathes of Photos stored on iPhone.

                One missing point: I also want to use the Photos as source of QML Image.
                Normaly this is working to display an Image using filePath from QFileInfo:

                        Image {
                            id: theImage
                            anchors.fill: parent
                            source: Qt.resolvedUrl("file://"+currentFile.path)
                            fillMode: Image.PreserveAspectFit
                        }
                

                but for files from iOS assets-library I’m getting

                QML Image: Cannot open: file://assets-library//asset/asset.PNG
                

                any idea HowTo provide a correct URL to Image ?

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #12

                Hi ekke,
                Have you considered writing a very lightweight C++ class for an image provider?

                Read and abide by the Qt Code of Conduct

                ekkescornerE 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  Hi ekke,
                  Have you considered writing a very lightweight C++ class for an image provider?

                  ekkescornerE Offline
                  ekkescornerE Offline
                  ekkescorner
                  Qt Champions 2016
                  wrote on last edited by
                  #13

                  @kshegunov said in Upload ios image with qt:

                  Have you considered writing a very lightweight C++ class for an image provider?

                  have thought about this
                  but was hoping that there's a way to construct an URL from QML
                  seems it isn't

                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                  5.15 --> 6.9 https://t1p.de/ekkeChecklist
                  QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                  kshegunovK 1 Reply Last reply
                  0
                  • ekkescornerE ekkescorner

                    @kshegunov said in Upload ios image with qt:

                    Have you considered writing a very lightweight C++ class for an image provider?

                    have thought about this
                    but was hoping that there's a way to construct an URL from QML
                    seems it isn't

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #14

                    @ekkescorner said in Upload ios image with qt:

                    but was hoping that there's a way to construct an URL from QML
                    seems it isn't

                    I think Thiago's objection goes more in the direction of security than anything else, as unless you're going to provide a full fledged parser that sanitizes the input (removing the special characters and so on) it's usually a bad idea to construct paths by parts manually. And this way you'd also wouldn't be able to benefit from any (security or other) patches that go into Qt's path handling.
                    If it were me I'd implement a basic provider on the C++ side, as it seems as the cleaner approach.

                    Read and abide by the Qt Code of Conduct

                    ekkescornerE 1 Reply Last reply
                    0
                    • kshegunovK kshegunov

                      @ekkescorner said in Upload ios image with qt:

                      but was hoping that there's a way to construct an URL from QML
                      seems it isn't

                      I think Thiago's objection goes more in the direction of security than anything else, as unless you're going to provide a full fledged parser that sanitizes the input (removing the special characters and so on) it's usually a bad idea to construct paths by parts manually. And this way you'd also wouldn't be able to benefit from any (security or other) patches that go into Qt's path handling.
                      If it were me I'd implement a basic provider on the C++ side, as it seems as the cleaner approach.

                      ekkescornerE Offline
                      ekkescornerE Offline
                      ekkescorner
                      Qt Champions 2016
                      wrote on last edited by
                      #15

                      @kshegunov finally I figured it out HowTo deal with iOS Images (Photos) without the need of creating an ImageProvider.

                      The file pathes are slightly different if you compare the filePath you got from C++ (QFileInfo) and the filePath you got from native iOS ImagePicker via QML FileDialog.

                      Getting the iOS Photos from C++

                      QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last() points to "assets-library://"
                      

                      QDir gives you a list of QFileInfo
                      Then it's easy to get the FilePath from C++ QFileInfo
                      will be something like this:

                      "assets-library://asset/asset.PNG?id=C6E6...77E9&ext=PNG"
                      

                      Coming the other way from QML use a special configured FileDialog:

                      import QtQuick 2.9
                      import QtQuick.Dialogs 1.2
                      FileDialog {
                          folder: shortcuts.pictures
                      }
                      

                      This FileDialog opens a native iOS Photo Picker
                      Select a File and get the FilePath:

                      theImage.source = myDialog.fileUrl
                      

                      FileUrl will be per ex:

                      "file:assets-library://asset/asset.PNG%3Fid=C6E6...77E9&ext=PNG"
                      

                      The QML path is needed to display the iOS asset as QML Image source,
                      the C++ path is needed to open the iOS asset from QFile

                      Conversion from QML to C++ Path:

                      QUrl url(path);
                      path = url.toLocalFile();
                      

                      Conversion from C++ to QML Path:

                      path = "file:"+fileInfo.filePath().replace("?","%3F")
                      

                      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                      5.15 --> 6.9 https://t1p.de/ekkeChecklist
                      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                      kshegunovK W 2 Replies Last reply
                      1
                      • ekkescornerE ekkescorner

                        @kshegunov finally I figured it out HowTo deal with iOS Images (Photos) without the need of creating an ImageProvider.

                        The file pathes are slightly different if you compare the filePath you got from C++ (QFileInfo) and the filePath you got from native iOS ImagePicker via QML FileDialog.

                        Getting the iOS Photos from C++

                        QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last() points to "assets-library://"
                        

                        QDir gives you a list of QFileInfo
                        Then it's easy to get the FilePath from C++ QFileInfo
                        will be something like this:

                        "assets-library://asset/asset.PNG?id=C6E6...77E9&ext=PNG"
                        

                        Coming the other way from QML use a special configured FileDialog:

                        import QtQuick 2.9
                        import QtQuick.Dialogs 1.2
                        FileDialog {
                            folder: shortcuts.pictures
                        }
                        

                        This FileDialog opens a native iOS Photo Picker
                        Select a File and get the FilePath:

                        theImage.source = myDialog.fileUrl
                        

                        FileUrl will be per ex:

                        "file:assets-library://asset/asset.PNG%3Fid=C6E6...77E9&ext=PNG"
                        

                        The QML path is needed to display the iOS asset as QML Image source,
                        the C++ path is needed to open the iOS asset from QFile

                        Conversion from QML to C++ Path:

                        QUrl url(path);
                        path = url.toLocalFile();
                        

                        Conversion from C++ to QML Path:

                        path = "file:"+fileInfo.filePath().replace("?","%3F")
                        
                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #16

                        @ekkescorner said in Upload ios image with qt:
                        Thanks for sharing the solution, ekke. There's something I find curious here, though:

                        "file:assets-library://asset/asset.PNG%3Fid=C6E6...77E9&ext=PNG"
                        

                        It's really surprising that only the ? is encoded in this case. I'd have expected all the special characters to be encoded according to URL rules. It's just odd. In any case for conversion from C++ to QML Path:

                        path = "file:"+fileInfo.filePath().replace("?","%3F");
                        

                        I'd research the possibility to use:

                        path = "file:"+ QUrl::fromLocalFile(fileInfo.filePath()).toString();
                        

                        or something of that nature. Especially if it's possible the local file is to be named in non-latin letters.

                        Read and abide by the Qt Code of Conduct

                        ekkescornerE 1 Reply Last reply
                        0
                        • kshegunovK kshegunov

                          @ekkescorner said in Upload ios image with qt:
                          Thanks for sharing the solution, ekke. There's something I find curious here, though:

                          "file:assets-library://asset/asset.PNG%3Fid=C6E6...77E9&ext=PNG"
                          

                          It's really surprising that only the ? is encoded in this case. I'd have expected all the special characters to be encoded according to URL rules. It's just odd. In any case for conversion from C++ to QML Path:

                          path = "file:"+fileInfo.filePath().replace("?","%3F");
                          

                          I'd research the possibility to use:

                          path = "file:"+ QUrl::fromLocalFile(fileInfo.filePath()).toString();
                          

                          or something of that nature. Especially if it's possible the local file is to be named in non-latin letters.

                          ekkescornerE Offline
                          ekkescornerE Offline
                          ekkescorner
                          Qt Champions 2016
                          wrote on last edited by
                          #17

                          @kshegunov yep - was surprising to me, too that only '?' is encoded. didn't found another way to manage this.
                          but for this special use-case there's no risk to get in trouble with non-latin letters because the filenames are pseudonames generated by iOS based on a UUID iOS generated

                          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                          5.15 --> 6.9 https://t1p.de/ekkeChecklist
                          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                          1 Reply Last reply
                          3
                          • ekkescornerE ekkescorner

                            @kshegunov finally I figured it out HowTo deal with iOS Images (Photos) without the need of creating an ImageProvider.

                            The file pathes are slightly different if you compare the filePath you got from C++ (QFileInfo) and the filePath you got from native iOS ImagePicker via QML FileDialog.

                            Getting the iOS Photos from C++

                            QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last() points to "assets-library://"
                            

                            QDir gives you a list of QFileInfo
                            Then it's easy to get the FilePath from C++ QFileInfo
                            will be something like this:

                            "assets-library://asset/asset.PNG?id=C6E6...77E9&ext=PNG"
                            

                            Coming the other way from QML use a special configured FileDialog:

                            import QtQuick 2.9
                            import QtQuick.Dialogs 1.2
                            FileDialog {
                                folder: shortcuts.pictures
                            }
                            

                            This FileDialog opens a native iOS Photo Picker
                            Select a File and get the FilePath:

                            theImage.source = myDialog.fileUrl
                            

                            FileUrl will be per ex:

                            "file:assets-library://asset/asset.PNG%3Fid=C6E6...77E9&ext=PNG"
                            

                            The QML path is needed to display the iOS asset as QML Image source,
                            the C++ path is needed to open the iOS asset from QFile

                            Conversion from QML to C++ Path:

                            QUrl url(path);
                            path = url.toLocalFile();
                            

                            Conversion from C++ to QML Path:

                            path = "file:"+fileInfo.filePath().replace("?","%3F")
                            
                            W Offline
                            W Offline
                            wild 0
                            wrote on last edited by
                            #18

                            @ekkescorner how to access ios system photo album;
                            0_1519720796661_83be4730-295e-4425-88d7-df2deadf7884-image.png
                            can you help me?

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved