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.3k 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.
  • H Offline
    H Offline
    hasti66
    wrote on 28 Oct 2014, 09:30 last edited by
    #1

    Hi , i use qt 5.3 on mac. I 've accessed to ios gallery with UIImagePickerController and i've get selected image url like this:
    assets-library://asset/asset.jpg?id=..&ext=jpg
    Now i want to upload this image on server. I converted the url to QString and called myUploadFunction(QString path). This function gets a path(that is a real path of image on device), creates a QFile, reads data from the file and posts data:
    @
    QFile *file = new QFile(path);
    file->open(OIDevice::ReadOnly);
    QByteArray fileData = file->readAll();
    ...
    networkAccessManager->post(...)
    @

    I know the upload method works on android and windows desktop. But in ios,i think i can not create a file from the image url (assets-library://asset/asset.jpg?id=..&ext=jpg). I need image actual path in ios. how can i get an image real path from it's url on ios to upload it?
    Thanks in advance

    Hasti Ranjkesh

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hasti66
      wrote on 29 Oct 2014, 09:21 last edited by
      #2

      I found a way to get an image file real path on ios from "here":https://github.com/questbeat/QBImagePickerController/issues/6
      path on simulator:
      file:///Users/mrsranjkesh/Library/Application Simulator/iPhone Simulator/7.0.3/Applications/9CB32.../Document/Koala.jpg
      When i give this path to my upload file, I get this error: QIODevice::read Device not open. When i tested file.exist(), i got "false"
      please reply. Thanks

      Hasti Ranjkesh

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ahmad88me
        wrote on 16 Sept 2015, 21:13 last edited by
        #3

        Did you manage to solve your problem.

        I'm facing the same problem. When I use FileDialog, fileUrl looks like "file:assets-library:/asset/asset.JPG%3Fid=78FD7629-DBEE-4279-ACAE-A54F1FEB9B58&ext=JPG" and I cannot assign this as an image source.

        B 1 Reply Last reply 18 Sept 2015, 05:03
        0
        • A ahmad88me
          16 Sept 2015, 21:13

          Did you manage to solve your problem.

          I'm facing the same problem. When I use FileDialog, fileUrl looks like "file:assets-library:/asset/asset.JPG%3Fid=78FD7629-DBEE-4279-ACAE-A54F1FEB9B58&ext=JPG" and I cannot assign this as an image source.

          B Offline
          B Offline
          benlau
          Qt Champions 2016
          wrote on 18 Sept 2015, 05:03 last edited by
          #4

          @ahmad88me Did you tried to use uri like "assets-library:/asset/asset.JPG%3Fid=78FD7629-DBEE-4279-ACAE-A54F1FEB9B58&ext=JPG" ?

          A 1 Reply Last reply 22 Sept 2015, 13:14
          0
          • B benlau
            18 Sept 2015, 05:03

            @ahmad88me Did you tried to use uri like "assets-library:/asset/asset.JPG%3Fid=78FD7629-DBEE-4279-ACAE-A54F1FEB9B58&ext=JPG" ?

            A Offline
            A Offline
            ahmad88me
            wrote on 22 Sept 2015, 13:14 last edited by
            #5

            @benlau Yes, still doesn't work

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zeecrowddev
              wrote on 1 Oct 2015, 10:59 last edited by zeecrowddev 10 Jan 2015, 11:00
              #6

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

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vi67
                wrote on 14 Nov 2015, 22:53 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 15 Nov 2015, 02:13 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 21 Dec 2015, 20:18
                  1
                  • V Vi67
                    15 Nov 2015, 02:13

                    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 21 Dec 2015, 20:18 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!

                    E 1 Reply Last reply 24 Oct 2017, 12:59
                    0
                    • R renatobibiano
                      21 Dec 2015, 20:18

                      @Vi67 said:

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

                      Thanks man, you saved me!

                      E Offline
                      E Offline
                      ekkescorner
                      Qt Champions 2016
                      wrote on 24 Oct 2017, 12:59 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.8 https://t1p.de/ekkeChecklist
                      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                      E 1 Reply Last reply 25 Oct 2017, 22:09
                      0
                      • E ekkescorner
                        24 Oct 2017, 12:59

                        @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 ?

                        E Offline
                        E Offline
                        ekkescorner
                        Qt Champions 2016
                        wrote on 25 Oct 2017, 22:09 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.8 https://t1p.de/ekkeChecklist
                        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                        kshegunovK 1 Reply Last reply 26 Oct 2017, 11:39
                        0
                        • E ekkescorner
                          25 Oct 2017, 22:09

                          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 26 Oct 2017, 11:39 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

                          E 1 Reply Last reply 26 Oct 2017, 13:05
                          0
                          • kshegunovK kshegunov
                            26 Oct 2017, 11:39

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

                            E Offline
                            E Offline
                            ekkescorner
                            Qt Champions 2016
                            wrote on 26 Oct 2017, 13:05 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.8 https://t1p.de/ekkeChecklist
                            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                            kshegunovK 1 Reply Last reply 26 Oct 2017, 13:24
                            0
                            • E ekkescorner
                              26 Oct 2017, 13:05

                              @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 26 Oct 2017, 13:24 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

                              E 1 Reply Last reply 30 Oct 2017, 14:30
                              0
                              • kshegunovK kshegunov
                                26 Oct 2017, 13:24

                                @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.

                                E Offline
                                E Offline
                                ekkescorner
                                Qt Champions 2016
                                wrote on 30 Oct 2017, 14:30 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.8 https://t1p.de/ekkeChecklist
                                QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                                kshegunovK W 2 Replies Last reply 31 Oct 2017, 12:44
                                1
                                • E ekkescorner
                                  30 Oct 2017, 14:30

                                  @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 31 Oct 2017, 12:44 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

                                  E 1 Reply Last reply 31 Oct 2017, 12:59
                                  0
                                  • kshegunovK kshegunov
                                    31 Oct 2017, 12:44

                                    @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.

                                    E Offline
                                    E Offline
                                    ekkescorner
                                    Qt Champions 2016
                                    wrote on 31 Oct 2017, 12:59 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.8 https://t1p.de/ekkeChecklist
                                    QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                                    1 Reply Last reply
                                    3
                                    • E ekkescorner
                                      30 Oct 2017, 14:30

                                      @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 27 Feb 2018, 08:40 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