0

I want to pass a CSV file type to an API in order to execute a POST and PUT requests. I'm using rest-assured and I tried to pass the file with the multiPart() method but it returns always HTTP code 400. Http code 200 is expected and a JSON with details as response.

Manually this is how the request looks like

curl -X POST "https://awesome/url" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "callbackUrl=https://sameAwesome/url" -F "[email protected];type=application/vnd.ms-excel" -F "fileFormat="csv"
0

1 Answer 1

1

The below should help

{
    String response = RestAssured.given().multiPart("file2", new File("C:\\Users\\alpha\\Desktop\\Test.csv")).
    when().post("http://localhost:3000/posts").then().extract().asString();
    System.out.println("Response is : " + response);
}

Reference link : https://blog.jayway.com/2011/09/15/multipart-form-data-file-uploading-made-simple-with-rest-assured/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.