# Using system.file.writeFile to save a PNG

**URL:** <https://forum.inductiveautomation.com/t/using-system-file-writefile-to-save-a-png/53205>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [November 17, 2021, 8:54pm UTC](https://forum.inductiveautomation.com/t/using-system-file-writefile-to-save-a-png/53205 "2021-11-17T20:54:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caleb\_Bohon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/caleb_bohon/32/3293_2.png) [@Caleb\_Bohon](https://forum.inductiveautomation.com/u/Caleb_Bohon)\
**Post date:** [November 17, 2021, 8:54pm UTC](https://forum.inductiveautomation.com/t/using-system-file-writefile-to-save-a-png/53205/1 "2021-11-17T20:54:44Z")

</div>

I’m calling an API to get a png in a python script. Then saving it to my computer using system.file.writeFile.

I am confident that the URL I am using is correct, because I have also used system.net.openURL to download the same PNG with my web browser.

Both resulting files are similar in size (both say 51k), but the GET file appears to have additional characters in it when compared with a text editor (notepad++).

I suspect the problem is the encoding part of the writeFile function. Is there an encoding that would work best for PNG, or BLOB files? Or what encodings are available? The user manual does not specify all of them. I’m trying all the ones mentioned.

OR is there a different function to use to write bytes to a file?

Here is part of my code:

```auto
png = system.net.httpGet(pngURL, headerValues=headerValues, usesCaches=0)

system.net.openURL(pngURL)

system.file.writeFile(filePath + ".png", png, 0, "ISO-8859-1")

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 17, 2021, 9:02pm UTC](https://forum.inductiveautomation.com/t/using-system-file-writefile-to-save-a-png/53205/2 "2021-11-17T21:02:56Z")

</div>

Don’t use `system.net.httpGet`, use `system.net.httpClient`.

The old functions assume you’re GETing String data. You can’t turn binary into a UTF-8 encoded String and back into binary and expect it to survive unmodified.

---

<div class="post-metadata">

**Author:** ![Caleb\_Bohon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/caleb_bohon/32/3293_2.png) [@Caleb\_Bohon](https://forum.inductiveautomation.com/u/Caleb_Bohon)\
**Post date:** [November 17, 2021, 9:19pm UTC](https://forum.inductiveautomation.com/t/using-system-file-writefile-to-save-a-png/53205/3 "2021-11-17T21:19:46Z")

</div>

Thanks Kevin. Additional breadcumbs for the next guy (or gal)…

after the getting a response, I also had to make sure I saved only the body of the response: here is my code snippet as modified:

```auto
client = system.net.httpClient()

#png = system.net.httpGet(pngURL, headerValues=headerValues, usesCaches=0)
png = client.get(pngURL)

print png

system.net.openURL(pngURL)

system.file.writeFile(filePath + ".png", png.body)

```
