0

I'm trying to configure and send a multipart request like the following one:

------boundary
Content-Disposition: form-data; name="before"; filename="blob"
Content-Type: application/vnd...+json;type=some_type

{some JSON}
------boundary
Content-Disposition: form-data; name="after"; filename="blob"
Content-Type: application/vnd...+json;type=some_type

{another JSON}
------boundary--

So I tried to configure a request, as in the code below

RestAssuredConfig config = RestAssured.config().multiPartConfig(
        new MultiPartConfig().defaultCharset(StandardCharsets.UTF_8).
                defaultBoundary("--boundary--"));
MultiPartSpecification m1 new MultiPartSpecBuilder(
        new ObjectMapper().writeValueAsString(some_JSON_transformed_to_HashMap)).
                fileName("blob").controlName("before").
                mimeType(ContentType.TEXT.getAcceptHeader()).
                header("ContentType", "application/vnd...+json;type=some_type").build();
MultiPartSpecification m2 = new MultiPartSpecBuilder(
        new ObjectMapper().writeValueAsString(another_JSON_transformed_to_HashMap)).
                fileName("blob").controlName("after").
                mimeType(ContentType.TEXT.getAcceptHeader()).
                header("ContentType", "application/vnd...+json;type=some_type").build();
RequestSpecification request = RestAssured.given().multiPart(m1).multiPart(m2).
        config(config).
          .header("Content-Type", "multipart/form-data; boundary=" + config.getMultiPartConfig().defaultBoundary());
request.post("some_url");

But when I try to execute it, server says that resource is invalid, but I believe, that JSONs is correct, so I suppose my multipart configuration is incorrect. How should I configure a request?

Alexei
  • 1
  • 1

1 Answers1

0

You could try something similar to below code .

given().auth().preemptive()
                .basic("Jirausername", "Jirapassword")
                .header("X-Atlassian-Token", "nocheck")
                .multiPart(new File("/home/users/cat.log"))
                .when().post("http://localhost:8181/rest/api/2/issue/STS-223/attachments"); 
Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41