Hi Team,
I have been trying to upload a file in a post api using katalon scripts but not able to do so. Below is the code that I am using to build my request. But not getting the desired response. Seems like the file is not getting posted.
@Keyword
def static requestBuilder(String url, String method, Map headerFields, String requestBody) {
‘Default contentType is “application/json”’
if (!headerFields.containsKey(‘Content-Type’)) {
headerFields.put(‘Content-Type’, ‘application/json’)
}
List header = new ArrayList()
for (Map.Entry<String, String> headerEntry : headerFields.entrySet()) {
header.add(new TestObjectProperty(headerEntry.getKey(), ConditionType.EQUALS, headerEntry.getValue()))
}
List formDataBdyparam=new ArrayList<>();
formDataBdyparam.add(new FormDataBodyParameter(‘file’,‘FileData\\asdf.html’ , ‘text’))
def builder = new RestRequestObjectBuilder()
//def requestObject = builder.withRestRequestMethod(method).withRestUrl(url).withHttpHeaders(header).withTextBodyContent(requestBody).build()
def requestObject = builder.withRestRequestMethod(method).withRestUrl(url).withHttpHeaders(header).withMultipartFormDataBodyContent(formDataBdyparam).build()
return requestObject
}
Is there any method available to provide the file as a parameter in the FormDataBodyParameter constructor?
I feel I am not passing correct parameters in the FormDataBodyParameter constructor because of which the withMultipartFormDataBodyContent is not working correctly.
I would also like to mention that the request is being posted and I am getting 401 response code back.
Please let me know how to proceed for the same.
Thanks
Anamika