I am doing an API automation of hp-alm using REST assured in Java. I'm trying to upload an attachment to a created run instance.
urlheaders.put("Content-Type", "multipart/form-data");
File file = new File("H:\\Desktop\\a.zip");
RequestSpecification httpRequest14 = RestAssured.given().headers(urlheaders).cookies(loginCookies).cookies(sessionCookies).multiPart( "file", file, "multipart/form-data");
Response attachment = httpRequest14.request(Method.POST,"/qcbin/rest/domains/d/projects/p/runs/13634/attachments");
String attachmentResponseBody = attachment.getBody().asString();
//logger.info("attachment Response Body is => " + attachmentResponseBody);
statusCode = attachment.getStatusCode();
logger.info("The attachment status code recieved: " + statusCode);
The status code is 500 and the error is:
File name and content should be supplied.
What does the error mean? Can anyone tell whats wrong in my code?
<div id="content-holder">
<h1>File name and content should be supplied</h1>
<div>
<tr>
<td><a id="exception-id-title">Exception Id:</a></td>
<td>qccore.general-error</td>
</tr>
</div>
</div>
Is there any method other then using rest assured to get desired output?
You have incorrect multipart request, you need to provide at least two parts: one which contains the file name, and one which contains the file itself.
Or you can use application/octet-stream Content-Type
instead.
See examples in the official docs.
Edit: working code: RestAssured.given().headers(urlheaders).cookies(loginCookies).cookies(sessionCookies).body(file);
And urlheaders must contain: