cancel
Showing results for 
Search instead for 
Did you mean: 

Image from oData is not fetched

nilesh_mishra1
Explorer
0 Kudos

Hi

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:

"/SampleServices/ESPM.svc/resources/images/HT-1000.jpg"

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

https://s2uqdnlqz93lrjbq205ld0eu-wpengine.netdna-ssl.com/wp-content/uploads/2016/07/Gala-single-nost...

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

Thanks

Nilesh

pfefferf
Active Contributor
0 Kudos

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).

nilesh_mishra1
Explorer
0 Kudos

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.

Thanks

Nilesh

Accepted Solutions (0)

Answers (2)

Answers (2)

aschlosser
Employee
Employee
0 Kudos

Nilesh,

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.

Thanks
Andreas

nilesh_mishra1
Explorer
0 Kudos

Hi Andreas,

I tried passing the same shown as below but result is still the same, I have changed httpMethod to GET as well, but somehow nothing happening.

aschlosser
Employee
Employee
0 Kudos

Nilesh,

You shouldn't add the /$value to the picture URL, but to the entity you're working on, something like /Products('HT-1000')/$value

The OData framework would do this automatically for you, if you use the `downloadMedia` API of the DataService class.

Thanks
Andreas

nilesh_mishra1
Explorer
0 Kudos

Hi Andreas,

Could you share some link with such examples, I think I am missing something. I am not too sure about how to use

`downloadMedia` API of the DataService class , if you can provide some link I can go through this and try to understand how to use it.

Thanks

Nilesh

aschlosser
Employee
Employee
nilesh_mishra1
Explorer
0 Kudos

Thanks Andreas,

Will check and try .

Nilesh

former_member484715
Contributor
0 Kudos

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.

Regards,

Arjun Biswas

nilesh_mishra1
Explorer
0 Kudos

Hi Arjun,

I tried passing the same shown as below but result is still the same.

former_member484715
Contributor
0 Kudos

Hi Nilesh Mishra,

Could you debug and check in the backend, if the data is comming or nor.

Regards,

Arjun Biswas.