0
votes

This is the api look like. I want to write a jmeter script to upload a csv file. I tried by putting Content-Type: multipart/form-data in HTTP header manager. then added parameter appId, fileName and putted an csv file in Files Upload tab in JMeter. But my response is showing 400 - bad request.

@POST
@Path("/{cid}")
@Consumes({ MediaType.MULTIPART_FORM_DATA,
        MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.APPLICATION_JSON})
public Response uploadFile(
        @Context UriInfo ui,
        @PathParam("cid") String cid,
        @QueryParam("appId") String appId,
        @FormDataParam("file") InputStream inputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail,
        @FormDataParam("fileName") String fileName,
        @Context SecurityContext securityContext) throws IOException {
           // code goes here

    }

enter image description here

1

1 Answers

1
votes
  1. Remove Content-Type header from the HTTP Header Manager
  2. Tick Use multipart/form-data box in the HTTP Request sampler

    enter image description here

In general the easiest way of generating proper HTTP Request sampler configuration for file uploading is just recording it using your favourite browser and JMeter's HTTP(S) Test Script Recorder. Just make sure that the file, you're uploading is present in JMeter's "bin" folder and JMeter should generate proper HTTP Request sampler so you won't have to do this manually. Check out Recording File Uploads with JMeter article for more information if needed.