0

I want to call a jdbc function through Jmeter and I am able to do it with simple function that takes text parameters but the function is slightly changed now and it takes parameter as bytea array of image. Please suggest how to browse an image from my PC local directory and how can I convert that image to byte array and pass that array to Jmeter jdbc call.

Nikunj Aggarwal
  • 754
  • 2
  • 12
  • 32

1 Answers1

0

I think that you should be able to use option 3 of How to Send Byte Array in http request in Jmeter solution, add a Beanshell PreProcessor as a child of your JDBC Request with code like

import org.apache.commons.compress.utils.IOUtils;

FileInputStream in = new FileInputStream("/path/to/your/image.jpg");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copy(in,bos);
byte[] data = bos.toByteArray();
vars.put("image", new String(data));

and refer image bytes as ${image} in the JDBC Request Sampler.

For advanced information on Beanshell scripting see How to use BeanShell: JMeter's favorite built-in component guide.

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133