0
votes

I'm trying to use JMeter to test a restful endpoint for uploading files, but I'm getting a 400 error. The one thing that jumps out at me is the boundary value; it's not the same I provided as the one shown in the request. I'm able to use the endpoint in the browser without issue, and I've replicated the headers revealed in the developer tools in FF.

Here is the relevant info from JMeter:

Result Tab:

Thread Name: Asdf - Load Test 1-1

Sample Start: 2017-06-05 08:47:46 EDT

Load time: 159

Connect Time: 28

Latency: 159

Size in bytes: 438

Sent bytes:821003

Headers size in bytes: 438

Body size in bytes: 0

Sample Count: 1

Error Count: 1

Data type ("text"|"bin"|""):

Response code: 400

Response message: Bad Request

Response headers:

HTTP/1.1 400 Bad Request

Date: Mon, 05 Jun 2017 12:47:46 GMT

Server: Apache/2.4.25 (Win64) OpenSSL/1.0.2k

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: 0

Strict-Transport-Security: max-age=31536000 ; includeSubDomains

X-XSS-Protection: 1; mode=block

X-Frame-Options: DENY

X-Content-Type-Options: nosniff

Cache-Control: no-cache, must-revalidate

Content-Length: 0

Connection: close

HTTPSampleResult fields:

ContentType:

DataEncoding: null

Request Tab:

POST https://localhost/my/rest/endpoint

POST data:

--9amm365-gMmimP70lvs9jIvlIxOfkocUN

Content-Disposition: form-data; name="parseable"; filename="asdf.docx"

Content-Type: application/vnd.openxmlformats-

officedocument.wordprocessingml.document

Content-Transfer-Encoding: binary

--9amm365-gMmimP70lvs9jIvlIxOfkocUN--

[no cookies]

Request Headers:

Connection: keep-alive

Content-Type: multipart/form-data; boundary=--Uc_2uLvcVgc7SqvzIJxR3encUKw- f7w9

Accept-Encoding: gzip, deflate, br

Accept-Language: en-US,en;q=0.5

Accept: application/json, text/plain, /

X-Request-OnBehalfOf: some-user-uuid

X-Requested-With: XMLHttpRequest

Content-Length: 820532

Host: localhost

User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)

Response Data Tab is blank.

Server side implementation:

@POST
@Override
@EnhancedDetail
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("my/rest/endpoint")
public Response uploadProduct(@PathParam("id") final String id, MultiPart multipart) throws IOException {
    return processMultiFileUpload(id, multipart, MultiPartUploadType.DRAFT, false);
}
2

2 Answers

1
votes

If you are building your request manually like it is described in Testing REST API File Uploads in JMeter article - make sure you have Use multipart/form-data for POST box of the HTTP Request sampler is not checked.

And vice versa, if you tick this box, you won't need to override the Content-Type header


I believe the easiest way would be just recording your file upload event using HTTP(S) Test Script Recorder (just make sure your asdf.docx file is copied to the "bin" folder of your JMeter installation)

1
votes

I figured it out. I changed the Client Implementation on the HTTP Request to Java. Everything I've read said use HttpClient4, but I tried Java and it worked.