Skip to Content

Image from oData is not fetched


I am trying to replicate Shopping cart with one of the few oData through SAP SDK for iOS.

I am able to fetch all the details but somehow Material Image is not getting fetched . The pathof Url in Odata is coming in parameter product.pctureurl as shown below:


func getDataFromUrl(url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {URLSession.shared.dataTask(with: url) { data, response, error incompletion(data, response, error)}.resume()}

But every-time Image is Blank. The value of data?.count is 3358

If I pass a normal URL in url like

as shown below, the value of Data?.count is 71180

The Output is, layout can be adjusted later

Kindly suggest what I am doing wrong, I am using Xcode 9.2 Swift4



code.png (110.5 kB)
data.png (78.9 kB)
normalurl.png (135.9 kB)
image-url.png (124.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • I think the issue here is that you are not successfully authenticated against the demo service endpoint and you get no valid image/* response, but a text/html response (you can check that in the reponse object), which cannot be converted to a UIImage of course. You can convert the data to a String to check the content, With the other URL it works, because no authentication is necessary and you get a valid image content type reponse.

    But to give you more feedback it would be necessary to know a little bit more about your app. Are you using a mobile service application with a valid endpoint? Do you do any authentication logic against SCP? ...

    If you have generated a proxy for the demo service in your app, you should use the downloadMedia API as suggested by Andreas. Constructing the URL manually with "$value" works, but is not the preferred way if a proxy is available. In addition your trial below with the "$value" addition is not correct, because you have constructed the wrong URL. You created a URL .../ESPM.svc/resources/images/HT-1000.jpg/$value which is wrong. If you do a GET request on the Products entity set you well see in the response a valid media link (for instance .../Products('HT-1000')/$value).

  • Hi Florian,

    I am basically trying to built a replica of Shopping Cart App, so authentication logic is written during on boarding which was taken care by SDK . I have not generated proxy for this service as I am not really sure with the structure of this oData so instead I am trying to read image directly from oData and showing it in App. My question is, do i need to handle authentication again if once it happens during Start of the App ?. Since the oData sends

    /SampleServices/ESPM.svc/resources/images/HT-1000.jpg in its parameter picturl and not the full Url. I have to build the whole URL again and tryng to fetch data from the URL. If I put this URL in Crome or any ither explorer it ask me Username and password and display me the image. I not very sure the correct approach to handle this scenario as I have just started learning swift .

    Kindly Suggest the proper way to fetch image or handle this scenario.



  • Get RSS Feed

2 Answers

  • Feb 05, 2018 at 07:06 AM


    Looks like you should maybe to a GET instead of POST to fetch the picture. For OData entities that have media resources, i.e. a $value property as Arjun is describing, you can use the `downloadMedia` API.


    Add comment
    10|10000 characters needed characters exceeded

  • Feb 05, 2018 at 04:43 AM

    Hi Nilesh Mishra,

    Could you try using $value with your URL. Usually you have to use this, when you are trying to fetch an media from the backend.


    Arjun Biswas

    Add comment
    10|10000 characters needed characters exceeded