如何在Jmeter中将图像字节数组传递给jdbc函数调用

时间:2015-03-16 13:37:32

标签: image jdbc jmeter bytearray

我想通过Jmeter调用一个jdbc函数,我可以用简单的函数来完成它,它接受文本参数,但是现在函数略有改变,它将参数作为图像的bytea数组。 请建议如何从我的PC本地目录浏览图像,如何将该图像转换为字节数组并将该数组传递给Jmeter jdbc调用。

1 个答案:

答案 0 :(得分:0)

我认为您应该能够使用How to Send Byte Array in http request in Jmeter解决方案的选项3,添加Beanshell PreProcessor作为JDBC请求的子代,其代码如

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));

并在JDBC Request Sampler中将图像字节引用为${image}

有关Beanshell脚本编写的高级信息,请参阅How to use BeanShell: JMeter's favorite built-in component指南。