Unable to upload file using REST API

I am trying to upload a csv file using REST API and Object Builder. Below is a snippet of my code (I am running it locally on my MacOS, filename is also called csv). Looking at the console, the request it is receiving is not formatted correctly.

=> {“csv”=>





“head”=>“Content-Disposition: form-data; name=\“csv\”; filename=\“csv\”\r\nContent-Type: application/octet-stream\r\n”},

Actual: {“csv”=>“csv”, “delete_mode”=>false}

Any help would be appreciated…Thanks!

def builder = new RestRequestObjectBuilder()

def requestObject = builder.withRestRequestMethod(‘POST’)

.withRestUrl(GlobalVariable.SUT + “/api/preprocess_csv”)


new TestObjectProperty(‘Content-Type’, ConditionType.EQUALS, ‘multipart/form-data’),

new TestObjectProperty(‘Cookie’, ConditionType.EQUALS, anpkSess.toString()),

new TestObjectProperty(‘Authorization’, ConditionType.EQUALS, ‘####’)])


new FormDataBodyParameter(“csv”, “csv”, “PARAM_TYPE_FILE”),

    new FormDataBodyParameter("csv", 'Content-Disposition: form-data; name="csv"; filename="csv"', "PARAM\_TYPE\_TEXT")


Resp = WS.sendRequest(requestObject)



Thanks, Nanda

Hello Experts,
Can you shed some light on this? I have tried various combinations but it still keeps returning an error saying that the field is invalid. If you could share some code which is working, it would be much appreciated. I really need help on this one as it is blocking automation of a majority of my test cases!

Hi @Swaminathan_Nandakum

We’re also having this problem, our workaround is to use cURL via ProcessBuilder instead.

ProcessBuilder pb = new ProcessBuilder(“curl”, “-X”, “POST”,
“-H”, ““Authorization: Basic tHiSiSaToKeN””
, “-H”, ““Content-Type: multipart/form-data””, “-H”, ““cache-control: no-cache””,
“-F”, ““attachment=@C:\test-image.jpg””)
Process p2 = pb.start();