djangid / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

support for multipart/mixed #220

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Setting the content type to multi-part/mixed and inserting multiParts() fails 
to output the body of the request. See forum 
https://groups.google.com/forum/#!topic/rest-assured/nzgFK8bKwqk

Summary:

expect().statusCode(200).given().contentType("multipart/mixed").multiPart("metad
ata", "file", mapper.writeValueAsBytes(doc2), 
"application/json").multiPart("filedata", "HelloWorld.txt", bis2, 
"text/plain").when().put("/documentstore-service/IHE:919191/sections/testSection
1");

doc2 is an object that can be JSON serialised and bis2 is an inputstream with a 
small amount of text available to the reader.

If I leave the contentType() out then it PUTs the whole body of the request 
with a type of multipart/form-data but when I put the content type in it looses 
the body of the request.

Original issue reported on code.google.com by bwalli...@gmail.com on 4 Mar 2013 at 12:25

GoogleCodeExporter commented 8 years ago
Perhaps you could try using the 
com.jayway.restassured.builder.MultiPartSpecBuilder and see if that works

Original comment by johan.ha...@gmail.com on 19 Nov 2013 at 6:47

GoogleCodeExporter commented 8 years ago
Closing because of no response from the issuer

Original comment by johan.ha...@gmail.com on 4 Jun 2014 at 1:38

GoogleCodeExporter commented 8 years ago
MultiPartSpecBuilder does not resolve the issue same type of error. I see only 
empty bodies on the wire.

Workaround build the body via http client classes:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
File upload = new File("upload.txt");
final String boundary = "-8<--- my simple boundary -->8---";
HttpEntity data = MultipartEntityBuilder.create()
   .setBoundary(boundary)
   .addTextBody("metadata", "{ \"foo\": \"bar\" }", org.apache.http.entity.ContentType.APPLICATION_JSON)
   .addBinaryBody("file", upload, org.apache.http.entity.ContentType.create("application/zip"), upload.getName())
                .build();
data.writeTo(bos);
ValidatableResponse response = given()
  .contentType("multipart/mixed; boundary=\"" + boundary + "\"")
  .body(bos.toByteArray())
  .post("/my-multi-part-mixed")
..... etc

Original comment by ric.kla...@gmail.com on 17 Apr 2015 at 8:57