Unable to create Multipart request with custom boundary

804 views
Skip to first unread message

Sara Raap-van Bussel

unread,
Nov 10, 2020, 5:51:25 AM11/10/20
to REST assured
Version used of RA: 4.3.0

My request spec:
public static RequestSpecification markLogicRequestSpec(){
return new RequestSpecBuilder()
.setAuth(digest("admin", "admin"))
.setConfig(config().encoderConfig(EncoderConfig.encoderConfig()
.appendDefaultContentCharsetToContentTypeIfUndefined(false)))
.setBaseUri(environment.getMarkLogicUrl())
.addFilter(new AllureRestAssured())
.build();
}


My request:
Asset response =
given().
spec(markLogicRequestSpec()).
contentType("multipart/mixed; boundary=johndoe").
multiPart("file", new File(getTestDataPath("test.png"))).
multiPart("file", new File(getTestDataPath("test.png"))).
when().
post(assetEndPoint).
then().
statusCode(201).
extract().as(Asset.class);


My logged request as a result of the code above:
Request method: POST
Proxy:                  <none>
Request params: <none>
Query params:   <none>
Form params:    <none>
Path params:    <none>
Headers:                Accept=*/*
                                Content-Type=multipart/mixed; boundary=johndoe
Cookies:                <none>
Multiparts:             ------------
                                Content-Disposition: mixed; boundary=johndoe; name = file; filename = test.png
                                Content-Type: application/octet-stream

                                testdata/test.png
                                ------------
                                Content-Disposition: mixed; boundary=johndoe; name = file; filename = test.png
                                Content-Type: application/octet-stream

                                testdata/test.png
Body:                   <none>

I have also tried adding config(RestAssuredConfig.config().multiPartConfig(multiPartConfig().defaultBoundary("abcdef"))). to either my SpecBuilder or in the given of the request, but that didn't change the boundary either.
I need to be able to set my boundary to anything else than just the basic -----------. What else can I try?

Michael Pinnegar

unread,
Nov 10, 2020, 1:23:04 PM11/10/20
to rest-a...@googlegroups.com
Rest assured has some examples using multi-part boundaries here in their test cases. Perhaps they can help illuminate if you're missing a chunk of config somewhere?
https://github.com/rest-assured/rest-assured/blob/22b3cf53166489b2ec9bddaf6cd64da2b21b224c/examples/rest-assured-itest-java/src/test/java/io/restassured/itest/java/presentation/MultiPartITest.java

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rest-assured/fc401245-559a-4c4b-bc9b-b7d3e0bf6261n%40googlegroups.com.

Sara Raap-van Bussel

unread,
Nov 11, 2020, 4:09:16 AM11/11/20
to REST assured
I tried all examples and none work. But I was also wondering about those tests. They add the boundary using either the content type or a config. But the assertion that the boundary is added only checks the addition of the boundary set in the content-type (which does work, also for me, see my example in my earlier message) but they never check if the boundary between the parts of the multipart is actually the boundary set (if that makes sense). So I don't know if the content type setting or the config setting are supposed to anything more than what I am seeing.

Op dinsdag 10 november 2020 om 19:23:04 UTC+1 schreef jaz...@gmail.com:

Michael Pinnegar

unread,
Nov 13, 2020, 9:48:49 AM11/13/20
to rest-a...@googlegroups.com
I agree with you about the tests. I think you might have found a bug in rest-assured, because even the test themselves aren't very good.

Reply all
Reply to author
Forward
0 new messages