How to send multipart data for file upload with json using REST Assured?

3,998 views
Skip to first unread message

webmintegrat...@gmail.com

unread,
Sep 10, 2015, 6:56:30 AM9/10/15
to REST assured
Hi All,

I am very new to Rest Assured. And i am trying to send multipart data for file upload with json.
Please help me out to forming the Rest Assured code.

Thanks in advance.

Regards,
Ramakant

Johan Haleby

unread,
Sep 10, 2015, 7:17:17 AM9/10/15
to rest-a...@googlegroups.com
Hi,

Here's one example:

// Given
final Message message = new Message();
message.setMessage("Hello World");

// When
given().
multiPart("controlName", message, "application/json").
when().
post("/multipart"). then(). statusCode(200);

Regards,
/Johan

--
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.
For more options, visit https://groups.google.com/d/optout.

webmintegrat...@gmail.com

unread,
Sep 10, 2015, 8:09:10 AM9/10/15
to REST assured
Hello Johan,

So many thanks for your quick reply.But i want to elaborate little bit more.
I have below palyload for mixed data::
First chunk of payload:
Content-Disposition: form-data; name="reference-data"; filename="blob"
Content-Type: application/json

{"integration":{"serviceData":{"referenceData":{"name":"ddd","description":"ddd","columnDelimiter":",","releaseCharacter":"\"","encodingType":"IBM437"}}}}

Second chunk of payload:

Content-Disposition: form-data; name="reference-data-file"; filename="RoleBasedAccessFeaturePlan.csv"
Content-Type: application/vnd.ms-excel

So  how to set content type to above payload?

If possible please add an example with code.

Regards,
Ramakant

siddalingesh Dhavalagi

unread,
Sep 11, 2015, 5:53:02 PM9/11/15
to REST assured
Hi Jhon,

can you send me example to include param and body contents with POST?

Thanks,
Siddu


On Thursday, September 10, 2015 at 4:47:17 PM UTC+5:30, Johan Haleby wrote:

Johan Haleby

unread,
Sep 16, 2015, 12:00:19 AM9/16/15
to rest-a...@googlegroups.com
Hi, 

You should be able to do something like this:

// Given
final Message message = new Message();
message.setMessage(
"Hello World");

// When
given().
multiPart(
new MultiPartSpecBuilder(greeting) .fileName("RoleBasedAccessFeaturePlan.csv") .controlName("reference-data-file") .mimeType("application/vnd.ms-excel").build()).
when().
post(
"/multipart"). then(). statusCode(200);

but REST Assured doesn't know how to serialize "application/vnd.ms-excel" so it won't work in your case. If you change it to "application/json" it works. It looks like it's not possible to configure how these content-types should be serialized for multiparts. I've added an issue for it here.

/Johan
Reply all
Reply to author
Forward
0 new messages