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 PreProcessor 可动态构建HTTP请求采样器有效负载,从而提供源文件夹,例如:
You can use Beanshell PreProcessor to dynamically build HTTP Request sampler payload providing source folder like:
- 将Beanshell PreProcessor添加为 HTTP请求采样器 >
-
将以下代码放入Beanshell PreProcessor的脚本"区域
- 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
参考文献:
sampler
- is shorthand for the HTTPSamplerProxy- HTTPFileArg
- How to Use BeanShell: JMeter's Favorite Built-in Component
这篇关于Jmeter多个文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!