multipartform-datarest-assuredmultipart

Uploading CSV file in Rest Assured returns 500


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

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.

enter image description here

enter image description here

On Postman it works fine I focused mainly of multipart/contentType part, but maybe the issue lies somewhere else?

enter image description here

Do you have any others ideas? I'd be very grateful

EDIT: POSTMAN console

enter image description here

enter image description here


Solution

  • 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();