Reputation: 299
I'm having issue with Jmeter using BeanShell PreProcessor to encode input file then include the encoded file in "Send file with request".
Jmeter Setup
BeanShell PreProcessor
import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;
String file1 = FileUtils.readFileToString(new File("D:/File/test.txt"),"UTF-8");
vars.put("file1",new String(Base64.encodeBase64(file.getBytes("UTF-8"))));
Error Message
java.io.FileNotFoundException: ${file1} (The system cannot find the file specified)
Upvotes: 0
Views: 2262
Reputation: 168157
If you're trying to do the following:
your Beanshell code should look like:
String file1 = FileUtils.readFileToString(new File("D:/File/test.txt"), "UTF-8");
FileUtils.write(new File("D:/File/testbase64.txt"),new String(Base64.encodeBase64(file1.getBytes("UTF-8"))));
vars.put("file1","D:/File/testbase64.txt");
Your code snippet was
file
JMeter variablefile.getBytes()
should be changed to file1.getBytes()
See How to use BeanShell: JMeter's favorite built-in component guide for more information on bsh scripting in Apache JMeter.
Upvotes: 1