I've been struggling to upload my CSV file via Rest Assured. It returns 500, while it works fine on Postman.
File myFile = new File("src\test\resources\myfile.csv");
response = given()
.spec(requestSpecification).config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
.multiPart("file", myFile,"multipart/form-data")
.when()
.post(endpoint)
.then().extract().response();
I also tried
without: encoderConfig & appendDefaultContentCharsetToContentTypeIfUndefined
with:
.body(file)
.contentType("text/csv")
also,
.config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("multipart/form-data", ContentType.MULTIPART)))
.contentType("multipart/form-data; boundary=--MyBoundary")
I think I've tried everything I found on the internet, but it still returns 500.
On Postman it works fine I focused mainly of multipart/contentType part, but maybe the issue lies somewhere else?
Do you have any others ideas? I'd be very grateful
EDIT: POSTMAN console
If you choose this method multiPart(String controlName, File file, String mimeType)
to upload, then the last parameter is mimeType "text/csv"
.multiPart("file", myFile, "text/csv");
full code:
File myFile = new File("src\\test\\resources\\myfile.csv");
response = given()
.spec(requestSpecification)
.multiPart("file", myFile, "text/csv")
.when()
.post(endpoint)
.then().extract().response();