# \[ResponseObject\] Cannot write binary content to file

**URL:** <https://forum.katalon.com/t/responseobject-cannot-write-binary-content-to-file/22454>\
**Category:** Feature Request\
**Tags:** feature-request, tracked, katalon-studio\
**Created:** [April 3, 2019, 8:49pm UTC](https://forum.katalon.com/t/responseobject-cannot-write-binary-content-to-file/22454 "2019-04-03T20:49:31Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 5, 2019, 9:45pm UTC](https://forum.katalon.com/t/responseobject-cannot-write-binary-content-to-file/22454/6 "2019-04-05T21:45:19Z")

</div>

Katalon’s ResponseObject is designed to process JSON/XML text only. It is not designed to process binary response. See [https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/testobject/ResponseObject.java](https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/testobject/ResponseObject.java) getResponseBodyContent()

If you want to download a binary dataf from URL in a Test Case of Katalon Studio, you should write a bit of Groovy script. Let me show you an example. Please make a test case with any name, copy & paste the following snippet, and run it. You will get an image file at `<projectDir>/temp/avator.png`

```auto
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

import com.kms.katalon.core.configuration.RunConfiguration

Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path tmpDir = projectDir.resolve('temp')
Files.createDirectories(tmpDir)
Path output = tmpDir.resolve("avator.png")

URL url = new URL("https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/48/333_2.png")

URLConnection connection = url.openConnection()
assert connection != null
println "connection.getContentLength()=" + connection.getContentLength()

InputStream is = new BufferedInputStream(connection.getInputStream())
OutputStream os = new BufferedOutputStream(new FileOutputStream(output.toFile()))

byte[] buffer = new byte[1024]
int n
while ((n = is.read(buffer)) > 0) {
	println "n=" + n
	os.write(buffer, 0, n)
	os.flush()
}

os.close()

```

---

_[View the full topic](https://forum.katalon.com/t/responseobject-cannot-write-binary-content-to-file/22454)._
