简体   繁体   中英

How to upload a file using REST API Put method using JMeter

Context of my query: Need to test REST API Put method for uploading a file tool to be used is JMeter.

I can successfully perform the above operation using POSTMAN tool but its not working in JMeter.

Here are the JMeter Request Details; method: PUT Path:path HEADER Content-Type= multipart/form-data; boundary=----WebKitFormBoundary${random}

BODY DATA

------WebKitFormBoundary${random} Content-Disposition: form-data; name="fileUpload"; filename="C:\\temp\\abc.zip" Content-Type: application/octet-stream

------WebKitFormBoundary${random}--

RESULTS: {"success":false,"errorMessages":"Request did not include an attachment"} Response code = 400

Appreciate if anyone can help or provide a better way to upload a file using PUT method.

Thanks, AB

Use MIME Type: application/zip

Your File Upload settings should look like this in JMeter:

在此处输入图片说明

My expectation is that you simply don't pass the file you are trying to upload along with the request. If you are building the request manually you will need to add the body of the file to your request using ie __FileToString() function. Check out Testing REST API File Uploads in JMeter article for more details.


Also given your request works in Postman you should be able to capture it using JMeter's HTTP(S) Test Script Recorder

  1. Copy the file you will be uploading using Postman to the "bin" folder of your JMeter installation
  2. Start JMeter's Proxy server. Refer JMeter Proxy Step by Step guide to learn how to do it.
  3. Start Postman using JMeter's HTTP(S) Test Script Recorder as a proxy by passing --proxy-server option to it like:

     C:\\Users\\your_user_name\\AppData\\Local\\Postman\\app-xxx\\Postman.exe --proxy-server=localhost:8888 
  4. Execute your request in Postman
  5. JMeter will store the captured request under Test Plan -> Thread Group -> Recording Controller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM