Reputation: 19
API signature :
@RequestMapping(value = "uploadImage", method = RequestMethod.POST, produces = {"application/sd-service", "application/json"})
@ResponseBody
public ImageUploadResponse uploadImage(@RequestParam(value = "channel", required=false) Channel channel, @RequestParam(value = "file") MultipartFile file, @RequestParam(value = "responseProtocol")Protocol responseProtocol)
I am using rest assured to send the following request to upload an image file .
Response res=RestAssured
.given()
.contentType("image/jpeg"
.body("{"responseProtocol":"PROTOCOL_JSON","channel":"WEB"}")
.multiPart(fileItem)
.when()
.log()
.all()
.post("http://x.y.z.a:8080/service/contactus/v2/uploadImage")
.andReturn();
where String userDir = System.getProperty("user.dir");
File fileItem= new File(userDir +"//src//main//resources//1.jpeg");
is the image file. But no results because of error mentioned below:
Getting org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: The current request is not a multipart request for below case:
Upvotes: 0
Views: 304
Reputation: 19
res = RestAssured
.given()
.contentType("multipart/form-data")
.accept("application/json")
.formParameter("channel", "WEB")
.formParameter("responseProtocol", "PROTOCOL_JSON")
.body(request.getBody())
.multiPart("file",fileItem,"image/jpeg")
.when()
.log()
.all()
.post(request.getURI())
.andReturn();
using form parameters solves it.
Upvotes: 1