vaibhav misra
vaibhav misra

Reputation: 135

How to upload an image file using Rest Assured framework?

I am trying to upload a file using the rest assured framework. The call is a POST call on the API that i am using and the code is mentioned below:

             given()
            .contentType("image/jpg")
            .accept("application/json")
            .auth().oauth2(accessToken, OAuthSignature.QUERY_STRING)
            .multiPart(new File("C:/Snap0000.jpg"))
            .post("/objects/files")
            .getBody();

The error that I get when doing this is:

400 - Unable to read image info Couldn't read magic numbers to guess format.

What am I doing wrong?

Upvotes: 2

Views: 6379

Answers (1)

Johan
Johan

Reputation: 40510

You may be missing the control name for the multipart? See javadoc for the multiPart method or look at the documentation.

Edit: above link is (partially) broken; this one at github seems to work better: https://github.com/rest-assured/rest-assured/wiki/Usage#multi-part-form-data

Upvotes: 1

Related Questions