Reputation: 1
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"
Upvotes: 0
Views: 6785
Reputation: 2774
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/
Upvotes: 1