Fileupload: content-type of mulitpart not in request?

1,363 views
Skip to first unread message

Tim

unread,
Sep 30, 2011, 4:55:43 AM9/30/11
to REST assured
Hello,

I'm trying to test a pdf-upload and when I compare the request from a
browser with the request from RestAssured, there seems to be a
difference which causes the test to fail (because the server can not
read the pdf).

Test code:
----------------
File f = new File(WORK_DIR + PDF_TEMPLATE);
Response response = given().
header("Accept", "text/html,application/xhtml+xml,application/
xml;q=0.9,*/*;q=0.8").
header("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7").
formParam("naam", naam).
formParam("tags", tags).
multiPart("pdf", f, "application/pdf").
when().post(BASE_URL + "rest/template/");

The RestAssured Request:
---------------------------------------
--XlMPMT1ptKPwSohV1ALhMDbyFCM6lBE-qSGFA
Content-Disposition: form-data; name="pdf";
filename="template_fietspadinspecties.pdf"

%PDF-1.7
%����
...

The corresponding browser request:
---------------------------------------------------
-----------------------------326212769225293
Content-Disposition: form-data; name="pdf";
filename="template_fietspadinspecties.pdf"
Content-Type: application/pdf

%PDF-1.7
%����
...

---> As you can see, the browser also sends "Content-Type: application/
pdf", RestAssured does not, although I specified it in
multiPart("pdf", f, "application/pdf").



Doest anyone knows how to fix this?


Thx,
Tim

Johan Haleby

unread,
Sep 30, 2011, 5:30:17 AM9/30/11
to rest-a...@googlegroups.com
Hi, 

I cannot seem to reproduce this. When I send a file like this:

given().
        multiPart("file", new File("/home/johan/devtools/java/projects/some_big.rar"), "application/pdf").
expect().
       statusCode(200).
when().
        post("/multipart/file");

and debug on the Server (using Scalatra + FileUpload support) it says that it finds the content type to be application/pdf.

/Johan

Tim Laeremans

unread,
Sep 30, 2011, 5:33:02 AM9/30/11
to rest-a...@googlegroups.com
Hello,

Is it possible you add a formparam to your test and post the request (or a part of it)?


Tim

2011/9/30 Johan Haleby <johan....@gmail.com>

Johan Haleby

unread,
Sep 30, 2011, 5:41:46 AM9/30/11
to rest-a...@googlegroups.com
I get the same result (i.e. the content type is found on the server) when I do like this:

given().
        header("Accept", "text/html,application/xhtml+xml,application/xmll;q=0.9,*/*;q=0.8").
        header("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7").
        formParam("param1", "value1").
        formParam("param2", "value2").
        multiPart("file", new File("/home/johan/devtools/java/projects/some_big.rar"), "application/pdf").
expect().
        statusCode(200).
when().
        post("/multipart/file");

Strange that it doesn't work for you..

/Johan

Johan Haleby

unread,
Sep 30, 2011, 7:04:29 AM9/30/11
to rest-a...@googlegroups.com
If you get any more clues on what could be causing it please let us know.

/Johan
Reply all
Reply to author
Forward
0 new messages