1

I have written a REST API, to upload file using multipart reuqest.

@RequestMapping(value = Constants.REQMAP_CON_FILE_UPLOAD, method = RequestMethod.POST, headers=("content-type=multipart/form-data"), consumes = "multipart/form-data" } )
        public @ResponseBody  
        HealthVaultResponse uploadFile(
                @PathVariable Long consumerFolderId,
                @PathVariable Long consumerUserId,
                @PathVariable Long reportTitleId,
                @RequestParam("file") MultipartFile file ,HttpServletRequest request) throws Exception {

------
------
}

It works fine with android app, but the web end is getting below error:

Client error: `POST http://172.16.2.67:8080/api/v1/uploadFile/1/0/5/` resulted in a `400 Bad Request` response:
{"status":{"statusCode":-400,"message":"Invalid Request, Media Type Not Supported","localizedMessage":"Invalid Request, (...)

What may be the problem?

Divya Nagrath
  • 139
  • 1
  • 2
  • 9
  • There is a problem with web code (javascript) because sent media type is not supported. it can be helpful https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_forms_through_JavaScript – Sunil Kanzar May 24 '17 at 10:53
  • I think this might help you - https://stackoverflow.com/questions/30681528/file-uploading-not-working-in-spring-mvc-using-spring-form – gajju_15 May 24 '17 at 10:53
  • What should be content-type on the web end? – Divya Nagrath May 24 '17 at 11:01

0 Answers0