hmpatel / rest-assured

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

Not able to upload an Image file using Mulitpart in Rest Assured #377

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Trying to upload a image(jpg) file using mulitPart option in Rest Assured 
2. given()
            .contentType("image/jpg")
            .accept("application/json")
            .auth().oauth2("accessToken",OAuthSignature.QUERY_STRING)
                .multiPart(new File("C:/Snap0000.jpg"))
            .post("/objects/files")
            .getStatusCode();
3.What is the expected output? What do you see instead?

Expected Code is 200.  I am getting 400. "Unable to read image info Couldn't 
read magic numbers to guess format."

What version of the product are you using? On what operating system?

2.4.0 on Win 7 64 bit

Please provide any additional information below.

Original issue reported on code.google.com by vaibhave...@gmail.com on 6 Dec 2014 at 7:08

GoogleCodeExporter commented 9 years ago
I was able to figure out the reason why I am facing this problem. When I 
mention the content type as "image/jpeg" or any content type as a matter of 
fact, REST Assured is adding the charset at the end of content type which is 
leading to this problem.

So what it actually sends in the header is :

Accept=application/json
Content-Type=image/jpeg; charset=ISO-8859-1

This extra string is causing the problem i am facing. Any suggestions as to how 
I can send just "image/jpeg" in content type without the charset thing.

An help would be appreciated.

Original comment by vaibhave...@gmail.com on 9 Dec 2014 at 10:20

GoogleCodeExporter commented 9 years ago
You can disable it using the EncoderConfig: 
https://code.google.com/p/rest-assured/wiki/Usage#Encoder_Config

I'm also thinking about not adding a charset by default since some people seem 
to have problems with it. Charset seems strange to add to a charset that is 
binary anyways so. I'll add an issue for it.

Original comment by johan.ha...@gmail.com on 30 Dec 2014 at 9:03