答案 0 :(得分:2)
您可以使用Beanshell PreProcessor动态构建HTTP请求采样器有效负载,提供源文件夹,如:
将以下代码放入Beanshell PreProcessor" Script"区域
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
File folder = new File("path_to_your_folder");
File[] files = folder.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile();
}
});
if (files != null) {
HTTPFileArg[] filesToUpload = new HTTPFileArg[files.length];
for (int i = 0; i < files.length; i++) {
HTTPFileArg fileToUpload = new HTTPFileArg(files[i].getPath(), "your_param", "your_mime_type");
filesToUpload[i] = fileToUpload;
}
sampler.setHTTPFiles(filesToUpload);
}
更改上述脚本中的以下字符串以符合您的环境:
path_to_your_folder
- 文件所在文件夹的完整或相对路径your_param
- 上传表单name
属性your_mime_type
- MIME type个文件参考文献: