Encode Attachments

Applies to ReadyAPI 3.56, last modified on November 21, 2024

ReadyAPI allows you to use Groovy scripts to work with attachments – for example, extract data from text files, change their encoding, and so on.

This topic describes how to use a Groovy script to encode attachments.

Where to use

There are several ways to run this script:

Example

The following code demonstrates how to encode the specific file with base64 in ReadyAPI:

Groovy

// Replace the file path with the one you need

// Get the file content
def inputFile = new File("C:\\Work\\MyFile.txt").getText('UTF-8')

// Encode the file content
String encoded = inputFile.bytes.encodeBase64().toString()

// Output results
log.info encoded // with the Groovy Script test step, you can use “return encoded”

See Also

Modify Responses
Parse JSON and XML
Groovy Script Test Step
Groovy Scripting Samples
Scripting

Highlight search results