Error downloading images on iOS devices

1076
3
Jump to solution
10-04-2019 03:49 AM
JorgeFrade_Martínez
New Contributor III

I can not download any image on iOS but works perfectly on Windows and Android.

NetworkRequest {
    id: networkRequest
    url: "https://example.example.com/api/currentimage"
    responsePath:AppFramework.userHomeFolder.filePath("ArcGIS/AppStudio/pipo.jpg")
    headers.json: {"My-Key": "PIPO"}
    property url imagePath: AppFramework.resolvedPathUrl(responsePath)
    
    onReadyStateChanged: {
        if ( readyState === NetworkRequest.DONE ) {
            //console.log("downloaded image")
            selected.obtainedImagePath = imagePath;
            busyIndicator.running=false;
            //console.log(imagePath)
            selected.mustUpdate = false;
        }
    }
}

Any idea?

0 Kudos
1 Solution

Accepted Solutions
StephenQuan1
Esri Contributor

Hi Jorge,

Thank you for your reply.

I have rewritten the example as a complete working application so you should no longer have issues running it.

In my of my code today, I now use the FileInfo object, with this:

  1. You get automatic shortcut to AppFramework.userHomePath via "~"
  2. You can get the physical path, i.e. FileInfo.filePath
  3. You can get the url (useful to assigning to Image.source), i.e. FileInfo.url
  4. You have access to the container folder via FileInfo.folder which is a FileFolder object which you can use to do folder operations, such as fileExists, delete, makeFolder

I hope you find this example more useful.

Stephen

View solution in original post

0 Kudos
3 Replies
StephenQuan1
Esri Contributor

Make sure the folder exists.

Use FileFolder.makeFolder() to do this.

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12

import ArcGIS.AppFramework 1.0

App {
    id: app

    width: 400
    height: 640

    property FileInfo target: FileInfo { filePath: "~/ArcGIS/AppStudio/Images/logo.png" }

    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 10

        Image {
            id: image
        }

        NetworkRequest {
            id: networkRequest

            url: "https://appstudio.arcgis.com/images/index/logo-appstudio.png"
            responsePath: target.filePath

            onReadyStateChanged: {
                if ( readyState !== NetworkRequest.ReadyStateComplete ) return;
                image.source = target.url
            }
        }

        Button {
            text: qsTr("Download Now")

            onClicked: {
                target.folder.makeFolder();
                networkRequest.send();
            }
        }

        Item {
            Layout.fillHeight: true
        }
    }
}
0 Kudos
JorgeFrade_Martínez
New Contributor III

The FileFolder don't have a property named filePath... That throws me an error.
If i change it to path, then throws this error:

TypeError: Property 'makeFolder' of object function() { [native code] } is not a function
Have you tried that code before posting it?

0 Kudos
StephenQuan1
Esri Contributor

Hi Jorge,

Thank you for your reply.

I have rewritten the example as a complete working application so you should no longer have issues running it.

In my of my code today, I now use the FileInfo object, with this:

  1. You get automatic shortcut to AppFramework.userHomePath via "~"
  2. You can get the physical path, i.e. FileInfo.filePath
  3. You can get the url (useful to assigning to Image.source), i.e. FileInfo.url
  4. You have access to the container folder via FileInfo.folder which is a FileFolder object which you can use to do folder operations, such as fileExists, delete, makeFolder

I hope you find this example more useful.

Stephen

0 Kudos