Problems using multipart/form-data in manual mode

Hello,

I am creating a POST request in manual mode and trying to attachment the file the I need in the multipart/form-data option but always I get the same error:

Could you help me please?

1 Like

Hello,

one of your parameters (ProcessId) is null and your server is not able to handle it, that’s why it returns 500 and throws an exception.

Thanks for your answer Marek, even with parameter not null is getting the same error

Where do you store your file? Is the specified path correct?

I am saving it in the next path, but in the Katalon explorer I dont see it and it is there look:

image

I need to pass parameterized values in the HTTP Body -> Form-data section How can I achieve that in Katalon?

Hi @ajaramillog , @Sudharsan

We’re also having issues with Katalon’s REST builder for multipart form data upload, the workaround we found for this is using cURL via ProcessBuilder

ProcessBuilder pb = new ProcessBuilder(“curl”, “-X”, “POST”,
“"https://samplesite/index.php?/api/v2/add_attachment_to_result/3996=\”",
“-H”, “"Authorization: Basic tHiSiSaToKeN"”
, “-H”, “"Content-Type: multipart/form-data"”, “-H”, “"cache-control: no-cache"”,
“-F”, “"attachment=@C:\test-image.jpg"”)
pb.redirectErrorStream(true)
Process p2 = pb.start();

Hi @mbillenberger,
Can you share your script? That will help us better investigate the issue.
Regards.

Hi @huynguyen

We’ve encountered this issue while trying to add TestRail’s attachment upload REST endpoint

Request for multipart/form-data:

RequestObject ro = new RequestObject(‘a’)
ro.setRestRequestMethod(‘POST’)
ro.setRestUrl(‘https://sampletestrailinstance/index.php?/api/v2/add_attachment_to_result/1378’)
def httpheader = new ArrayList()
httpheader.add(new TestObjectProperty(‘Content-Type’, ConditionType.EQUALS, ‘multipart/form-data’))
httpheader.add(new TestObjectProperty(‘Authorization’, ConditionType.EQUALS, auth))
ro.setHttpHeaderProperties(httpheader)
def formdataparam = new FormDataBodyParameter(‘attachment’, ‘C:\test-image.jpg’, ‘File’)
ro.setBodyContent(new HttpFormDataBodyContent([formdataparam]))
def response = WS.sendRequest(ro)
println(response.getResponseText())

Response for multipart/form-data:

Note: This is the response from TestRail when submitting a blank body

Which may mean that the image is not attached to the FormDataBodyParameter, I can’t really tell for sure because the RequestObject doesn’t return the request used when it’s executed.

If I use this same code, but Content-Type: application/json, it works, which means my header is not the issue.

Request for application/json

RequestObject ro = new RequestObject(‘a’)
ro.setRestRequestMethod(‘GET’)
ro.setRestUrl(‘https://sampletestrailinstance/index.php?/api/v2/get_tests/55’)
def httpheader = new ArrayList()
httpheader.add(new TestObjectProperty(‘Content-Type’, ConditionType.EQUALS, ‘application/json’))
httpheader.add(new TestObjectProperty(‘Authorization’, ConditionType.EQUALS, auth))
ro.setHttpHeaderProperties(httpheader)
ro.setBodyContent(new HttpTextBodyContent(‘’, ‘UTF-8’, ‘application/json’))
def response = WS.sendRequest(ro)
println(response.getResponseText())

Response for application/json:

Did this start working for you?
I am doing the same thing and for same purpose (Test Rail result updating with screenshot)