首页 > 解决方案 > 在 Jmeter 中将图像转换为 base64

问题描述

我是 Jmeter 的新手,需要一些指导。我正在尝试从目录中读取大量图像,并且需要在 Jmeter 中将每张图片转换为 base64。如果我理解正确,我可以在 HTTP 请求中使用 __FileToString。但是,我需要先转换它然后传递给请求。我曾尝试使用 ForController 并按照 Internet 上的说明使用 BeanShell Sampler 进行转换,但图像出现损坏。你能指导我怎么做吗?谢谢。

标签: jmeterbase64beanshell

解决方案


I've heard Groovy is the new black, moreover you should not be using Beanshell since JMeter 3.1

So you can convert an image into its Base64 representation using __groovy() function like:

${__groovy(new File('/path/to/your/image.png').bytes.encodeBase64().toString(),)}

推荐阅读