Upload file issue

443 views
Skip to first unread message

Mike

unread,
Mar 21, 2018, 12:39:12 AM3/21/18
to REST assured

Hi,

I’m using RA 3.0.7 and I have issue when trying to upload file.

The code (Java) I’m using is:

given()
        .header(
"Cookie", <cookie>).
        formParam(
"hdnSelectedTool", "abc").
        formParam(
"hdnIsOverride", false).
        multiPart(
"fileToUpload", fileToUpload).
when().
post(
<url>);

 

My problem is the server gets ‘Content-Transfer-Encoding: 8bit\n’ string as prefix for each param I pass in the request.

For example, I pass hdnSelectedTool=abc, but the server gets hdnSelectedTool= Content-Transfer-Encoding: 8bit\n abc

 

Did someone encounter this issue and know how to deal with it?

 

Thanks in advance

Omnipotent Krishna

unread,
Jul 30, 2018, 11:45:48 AM7/30/18
to REST assured
Hi,
Yes, I am also facing similar kind of issue, in my case content type is taking to application/octet-stream.

Regards,
Krishna

George Louis Dela Cruz

unread,
Nov 9, 2018, 1:49:34 AM11/9/18
to REST assured
Hello,

also facing this kind of problem when uploading file with parameters assigned to it.

given()
.param("authorName", reader.getAuthorNameValue())
.param("file",new File(reader.getFilePath()))
.when().log().all()
.post(reader.getsaveContenturl())
.then()
.statusCode(200).log().all();
Regards,
George

Johan Haleby

unread,
Nov 12, 2018, 2:55:13 AM11/12/18
to rest-a...@googlegroups.com
Try using "multiPart" instead of "param" for the file.

--
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.

George Louis Dela Cruz

unread,
Nov 12, 2018, 3:16:12 AM11/12/18
to REST assured
problem solved. i just used .multipart("file", new File(filepath), mimeType)

thanks!!

hanumesh

unread,
Aug 11, 2020, 8:16:51 AM8/11/20
to REST assured
I am unable to upload file in REST assured tests. The upload works fine in Postman though.
Here is the sample: 

     Response res = 

given()

    .headers( "Authorization", "Bearer " + jwtToken)

    .contentType("application/vnd.ms-excel")

    .multiPart("file", new File("testdata/sod_portfolio/FI_TRADES_20200810.csv"), "application/vnd.ms-excel")

    .when()

.post(url);


ERROR:

java.lang.IllegalArgumentException: Content-Type application/vnd.ms-excel is not valid when using multiparts, it must start with "multipart/" or contain "multipart+".


Also tried the following:

      String response = RestAssured.given()

        .multiPart("file", new File("testdata/testMyData.csv"), "application/vnd.ms-excel" )

        .when().

        post(url).

        then().extract().asString();

             System.out.println("Response is : " + response); 

But I am not able to upload successfully.


Appreciate your response if anybody has automated the upload functionality.

Thanks




hanumesh

unread,
Aug 11, 2020, 8:16:59 AM8/11/20
to REST assured
Hi
I also have problem testing file upload in my test framework (RESTAssured(4.3.0), TestNG(7.1.0), java 1.8)
Here is the code snippet:

given()

    .headers( "Authorization", "Bearer " + jwtToken)

    .contentType("application/vnd.ms-excel")

    .multiPart("file", new File("testdata/myFile_20200810.csv"), "application/vnd.ms-excel")

    .when()

.post(url);


Error:

java.lang.IllegalArgumentException: Content-Type application/vnd.ms-excel is not valid when using multiparty, it must start with "multipart/" or contain "multipart+".



I also tried replacing multipart/form-data instead of application/vnd.ms-excel but no luck. If anybody has done similar please let me know.

Thank you,
Hanumesh


On Monday, 12 November 2018 at 00:16:12 UTC-8 George Louis Dela Cruz wrote:
Reply all
Reply to author
Forward
0 new messages