Image JMeter-为PUT请求从数据文件读取图像

Image JMeter-为PUT请求从数据文件读取图像,image,rest,jmeter,put,data-files,Image,Rest,Jmeter,Put,Data Files,我有一个csv数据作为 FirstName,MiddleName,LastName,ImageLocation Jack|Michel|Rechards|C:\Image\picture.jpg Tom|Peter|Kim|C:\Image\picture123.jpg 我正在尝试配置Jmeter来读取上面的数据文件,并将图像作为表单数据传递给RESTAPI PUT资源作为表单数据。API接受图像作为ByteBuffer 在JMeter中,多部分/表单数据上载仅可用于POST,而不可用于PUT

我有一个csv数据作为

FirstName,MiddleName,LastName,ImageLocation
Jack|Michel|Rechards|C:\Image\picture.jpg
Tom|Peter|Kim|C:\Image\picture123.jpg
我正在尝试配置Jmeter来读取上面的数据文件,并将图像作为表单数据传递给RESTAPI PUT资源作为表单数据。API接受图像作为ByteBuffer

在JMeter中,多部分/表单数据上载仅可用于POST,而不可用于PUT资源

对于Image,我在BeanShell预处理器中编写了一段代码,将byte[]放入变量中

String imageLoc = vars.get("ImageLocation");
File file = new File(imageLoc);
byte[] buffer = new byte[(int) file.length()];
InputStream ios = null;
    try {
        ios = new FileInputStream(file);
        if (ios.read(buffer) == -1) {
            throw new IOException(
                    "EOF reached while trying to read the whole file");
        }
    } finally {
        try {
            if (ios != null)
                ios.close();
        } catch (IOException e) {
        }
    }
vars.put("imageData", new String(buffer));
并且变量imageData在HTTP请求主体数据中作为

------=_parttest
Content-Type: image/jpeg; name=test.jpeg
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="Picture"; filename="test.jpeg"
${imageData}
------=_parttest--
由于某些原因,Jmeter的请求无法正确呈现图像。若我向API发出类似的邮递员PUT请求来保存图像,并发出另一个GET请求来读取图像,那个么它就被成功读取了

要么我没有正确配置测试(beanShell代码问题或HTTP请求正文数据问题),要么有更好的方法来配置此测试,以便从数据文件中的路径读取图像,并将图像作为表单数据传递给API PUT资源


期待专家的建议。

实际上可以使用JMeter执行多部分PUT请求,您需要:

  • 添加并将其配置为发送值为的标头:

    multipart/related; boundary=parttest
    
  • 使用与
    内容类型
    标题中相同的边界值在中构造请求正文
  • 请参阅使用PUT请求更新Google Drive中文档的示例测试计划,您可以将其用作参考

    此外,我建议您使用函数来读取图像文件内容,或者如果您更喜欢脚本,请选择