Memory Issue with encoding a file to base64
Hi,
I am able to encode a file to base64 using groovy script however it gives memory issues. Is there a way to do this so memory is not affected? I would like to achieve this using groovy, not using the attachments functionality in the request
Below is the code I am currently using that works but with memory issues. Example file location: C:\Users\Public\Pictures\Sample Pictures\Desert.jpg
import org.apache.commons.codec.binary.Base64;
String filePath = testRunner.testCase.testSuite.project.getPropertyValue("filePath")
File fileName = new File(filePath);
String encodedBase64 = null;
FileInputStream fileInputStreamReader = new FileInputStream(fileName);
byte[] bytes = new byte[(int) fileName.length()];
fileInputStreamReader.read(bytes);
encodedBase64 = new String(Base64.encodeBase64(bytes));
fileInputStreamReader.close();
testRunner.testCase.testSuite.project.setPropertyValue("encodedFilePath", encodedBase64)
Thanks,
Rory