sahaya / rest-assured

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

Upload File is not working using Multipart #351

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I am trying to upload an XML file to the server but getting 400 instead of 200. 
Upon some debugging at server side, looks like "filename" (tested with file on 
local drive and also on eclipse project) is empty.

I browsed on the net and see some issues regarding this. Just want to know if 
this issue still exists or there is a work around.

Thanx,

String path = "/file/upload/parameterfile?deviceType=Kronos InTouch"; 
//&uploadType=multipart
String infoValue = "{\"options\": {\"fileType\": \"SET\"}}";
String fileName = "C:\\Keshav\\getAllPayCodes.xml"

_response = given().
            auth().preemptive().basic(Constants.USER_NAME, Constants.PASSWORD).
            contentType("multipart/form-data").
            multiPart("file", new File(fileName), "multipart/form-data").
            formParam("info", infoValue).
        //expect().
                //body("status", 200).
        when().
            post(path);
What is the expected output? What do you see instead?
XML file should be uploaded

What version of the product are you using? On what operating system?
rest-assured 2.3.2/Windows 7

Please provide any additional information below.

Original issue reported on code.google.com by krao03 on 28 Aug 2014 at 8:38

GoogleCodeExporter commented 9 years ago
I cannot reproduce this.  When I upload a file using new File(..) the file name 
is correct. See for example 
com.jayway.restassured.itest.java.presentation.MultiPartITest#simpleFileUploadin
g. 

I would more info, preferably a small gradle or maven project that demonstrates 
the issues.

Original comment by johan.ha...@gmail.com on 29 Aug 2014 at 6:29

GoogleCodeExporter commented 9 years ago
I've tried updating the HTTP Client dependency to the latest version (4.3.5) 
and then I got the same error as you do! REST Assured 2.3.2 shipped with HTTP 
Client 4.2.6 and it work in that version. The problem is that HttpClient has 
changed they way they handle empty file names in 
org.apache.http.entity.mime.content.FileBody. Previous http client extracted 
the file name from the file if no explicit file name were defined which was no 
longer the case in 4.3.5. So I've fixed this in the master branch now.

Original comment by johan.ha...@gmail.com on 29 Aug 2014 at 1:15

GoogleCodeExporter commented 9 years ago
Thanx,

I tried running code with REST Assured 2.3.3 and HTTP Client 4.3.5 and still 
see same issue. Am I missing anything ?

Original comment by krao03 on 30 Aug 2014 at 3:57

GoogleCodeExporter commented 9 years ago
Don't know, perhaps there's something wrong on the server side!? If it's 
possible to create a Maven/Gradle project that demonstrates the issue I could 
look into it.

Original comment by johan.ha...@gmail.com on 30 Aug 2014 at 6:14

GoogleCodeExporter commented 9 years ago
Thanx John, This issue is fixed.

Original comment by krao03 on 15 Sep 2014 at 7:37