Image is not storing into device.

520
2
03-25-2021 05:59 AM
x_d
by
New Contributor III

Hi, I tried  to download an image from server and store it locally on the first page and then on second page i tried to show that image using the local path(where the downloaded image is stored) . I tested this example on desktop and on my mobile using appstudio player. It is working fine over there but on android it is not working. the image does not get saves to the path. 

Here is the First_page page1.qml

Page{
    id: app
    FileInfo {
            id: destData
            url: "~"
        }
//Downloads an image from the web
NetworkRequest {
    id: networkRequest
    url: "http://appstudio.arcgis.com/images/index/introview.jpg"
    responsePath: destData.path +"/appstudio.jpg"
    property url imagePath: responsePath

   onReadyStateChanged: {
        if (readyState == NetworkRequest.DONE) {
       }
    }
    onError: {
        console.log(errorText + ", " + errorCode)
        image.source = ""
    }
}

Column{
    Layout.alignment: Qt.AlignHCenter
    spacing: 70 
    Layout.rightMargin: 20
    Image {
        id:btn_pre
        source: "../../assets/images/btn_pre.png"
        MouseArea{
            anchors.fill: parent
            onClicked: {
                stackView.push("page2.qml");
                             }
        }
    }
    ColumnLayout {
        spacing: 20
        Button {
            id:download
            text: "Download Request (Download Image)"
            Layout.margins: 2
            Layout.fillWidth: true
            onClicked: {
                networkRequest.send({f:"json"});
            }
        }
    }
}
}
[[And Here is Second_page page2.qml]]
Page{
    id: apptest
    Column{
        spacing: 50
    Row{
        Layout.alignment: Qt.AlignHCenter
        Layout.topMargin:20
        spacing: 70
        Layout.rightMargin: 20
        Image {
            id:btn_pre
            source: "../../assets/images/btn_pre.png"
            MouseArea{
                anchors.fill: parent
                onClicked: {
                      stackView.pop()
                 }
            }
        }
    }
    Image {
        id: image
        Layout.margins: 10
        width: 200
        height: 400
        source: "appstudio.jpg"
    }
    }
}
Tags (2)
0 Kudos
2 Replies
ErwinSoekianto
Esri Regular Contributor

@x_d 

 

Can you try this below?

 

 

On the NetworkRequest { responsePath: destData.fileUrl("appstudio.png")

And the when you access it on the Image { source: destData.fileUrl("appstudio.png")

 

Thank you,

Erwin

0 Kudos
x_d
by
New Contributor III

I'm getting this error,

  {{

Property 'fileUrl' of object FileInfo(0x1c95f5581b0) is not a function

}}

0 Kudos