Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to load a secure html image in a Text item



  • I have an application that is displaying html text from a secure server (Jira), this text will sometimes have images:

    <span class="image-wrap" style=""><img src="/secure/attachment/10000/10000_reply.png" height="17" width="22" style="border: 0px solid black" /></span>
    

    I am stuck as to how to actually display these images.
    By default it gives the obvious error:

    qrc:/IssueDetails.qml:90:9: QML QQuickText: Cannot open: qrc:/secure/attachment/10000/10000_reply.png
    

    My first thought was to replace the path with the full https://, but that gives a blank image as the image requires authorization.
    I have confirmed the image exists and can be accessed by downloading it, but I can't them embed that in some html unless I download it to disk somewhere

    Next I set the authentication cookie on the root networkaccessmanager, no luck,
    also tried setting a network proxy with no avail.

    Any advice?


  • Moderators

    @Mr-MinimalEffort
    implement a custom QQuickAsyncImageProvider and retrieve the image there from https

    Next I set the authentication cookie on the root networkaccessmanager, no luck,

    this will only work if you use QQmlNetworkAccessManagerFactory



  • Thanks @raven-worx sorry for the late reply, I apparently had notifications off.
    QQuickAsyncImageProvider will only work for Image components, not Text with html text.

    Is there a way I can connect an image provider to a Text component?

    I tried QQmlNetworkAccessManagerFactory but no luck there either, I think I may be missing some cookies in order to process the request and may need to check in with the Atlassian Developers


  • Moderators

    @Mr-MinimalEffort said in How to load a secure html image in a Text item:

    I tried QQmlNetworkAccessManagerFactory but no luck there either, I think I may be missing some cookies in order to process the request and may need to check in with the Atlassian Developers

    yes you need the cookies (authentication) in any case, no matter what when you want to send requests to the webserver.



  • Yes, Jira provides an authentication user/accessKey to attach to each request, by passing this information alongside a get request I can access the image data fine, I just can't figure out how to hijack an image request coming from a qml Text item with the image embedded in html.
    My last ditch effort would be to download the image and replace the <img src tag with the dataUrl, though I'm not sure what the overhead of that would be


  • Moderators

    @Mr-MinimalEffort
    what QML element are you using to display the HTML content?
    And on what platform?


  • Qt Champions 2018

    @Mr-MinimalEffort using a QQmlNetworkAccessManagerFactory that returns a custom QNetworkAccessManager that adds the relevant cookies to your requests should work, I've done it in the past.



  • Ah sorry @raven-worx I thought I had it in my example but I did not.

    Text {
        id: descriptionLabel
        text: "Description:"
        font.bold: true
        wrapMode: Text.Wrap
        textFormat: Text.RichText
        text: "<p><span class=\"image-wrap\" style=\"\"><img src=\"https://ommitted.atlassian.net/secure/attachment/10000/10000_reply.png\" height=\"17\" width=\"22\" style=\"border: 0px solid black\" /></span></p>"
    }
    

    Running on Windows 10

    @GrecKo yes I suspect the cookies are being added correctly but I just have the wrong cookies and will need to discuss with atlassian


Log in to reply