Jmeter多文件上传 [英] Jmeter multiple file uploads
问题描述
一个简单的问题,我希望.
A simple question, I hope.
JMeter 版本:3.0
JMeter version: 3.0
如何一次上传多个文件,而不是逐个选择?我想在单个请求中上传大约 1000 个文件,并且似乎需要很长时间才能使用当前的用户界面进行设置.
How to include several files for upload at once, instead of selecting on a per file basis? I want to upload around 1000 files in a single request, and it will take forever to set up with the current user interface it seems.
推荐答案
您可以使用 Beanshell预处理器动态构建 HTTP 请求采样器有效负载,提供源文件夹,如:
You can use Beanshell PreProcessor to dynamically build HTTP Request sampler payload providing source folder like:
- 将 Beanshell 预处理器添加为 HTTP 请求 采样器的子项
将以下代码放入Beanshell PreProcessor的Script"区域
- Add Beanshell PreProcessor as a child of the HTTP Request sampler
Put the following code into the Beanshell PreProcessor's "Script" area
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);
}
更改上述脚本中的以下字符串以匹配您的环境:
Change the the following strings in the above script to match your environment:
path_to_your_folder
- 文件所在文件夹的完整或相对路径your_param
- 上传表单name
属性`your_mime_type
- 文件的MIME类型
path_to_your_folder
- full or relative path to folder where your files liveyour_param
- to upload formname
attribute`your_mime_type
- to MIME type of the files
参考文献:
这篇关于Jmeter多文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!