# Get an Image from REST-Service

**URL:** <https://forum.servoy.com/t/get-an-image-from-rest-service/20695>\
**Category:** Questions\
**Created:** [February 24, 2022, 1:48pm UTC](https://forum.servoy.com/t/get-an-image-from-rest-service/20695 "2022-02-24T13:48:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rph](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rph](https://forum.servoy.com/u/rph)\
**Post date:** [February 24, 2022, 1:48pm UTC](https://forum.servoy.com/t/get-an-image-from-rest-service/20695/1 "2022-02-24T13:48:49Z")

</div>

Hi

We call a webservice and the content-type of the response is “image/png” and the content-disposition is ‘attachment; filename= "snapshot.png’. In Postman the Image will be shown in the “Body”-Tab after the successfull call of the webservice.

I try now to do this with the Servoy “plugins.http” and to store the content in a file, so I can store it somewhere (file or db).

The webservice works so far, but I dont know how to handle the response. response.getMediaData() returns null, but response.getResponseBody() returns a String that starts with “PNG\r\n…”.

What do I have to do now with this String? How do I have to “convert” it, so I can store it in a file?

I’ve tried to write it down with “plugins.file.writeTXTFile”. This create a file that is exactly as large as if I story the response in Postman but there are a few special characters in the file that looks different. So obiously there are some “encoding” issues.

Any ideas will be very appreciated.

Best  
Roland

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [February 26, 2022, 12:42pm UTC](https://forum.servoy.com/t/get-an-image-from-rest-service/20695/2 "2022-02-26T12:42:54Z")

</div>

Hi Roland,

You can only use one of response.getResponseBody() or response.getMediaData() since they both consume the contents of the response.

Try calling response.getMediaData() **without** calling response.getResponseBody() first, this should return the actual bytes of your image.

Hope this helps,

Rob

---

<div class="post-metadata">

**Author:** ![rph](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rph](https://forum.servoy.com/u/rph)\
**Post date:** [February 28, 2022, 8:31am UTC](https://forum.servoy.com/t/get-an-image-from-rest-service/20695/3 "2022-02-28T08:31:40Z")

</div>

Hi Rob

Thanks a lot for your reply. This does the trick!

My problem was, that I had “response.getResponseBody()” in the debugger-perspective in the “Expression”-View. And as I debug through the code, I had a breakpoint and step through the code. But the expression was directly resolved after I got the response and before response.getMediaData() was executed and so response.getMediaData always returned “null”. ![:roll:]( "Rolling Eyes") ![:roll:]( "Rolling Eyes")

Thanks again and have a nice day.  
Best  
Roland
