Upload ios image with qt
-
@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 ?
-
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 ?
-
Hi ekke,
Have you considered writing a very lightweight C++ class for an image provider? -
@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 -
@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'tI 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. -
@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 QFileConversion from QML to C++ Path:
QUrl url(path); path = url.toLocalFile();
Conversion from C++ to QML Path:
path = "file:"+fileInfo.filePath().replace("?","%3F")
-
@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.
-
@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 -
@ekkescorner how to access ios system photo album;
can you help me?