1

I have made a post mapping in spring boot to pass all the field values of my pojo from form-data of postman. One of the fields involves uploading a file which is handled by multipartfile.

I am getting an internal server error in postman when running this method

@RequestMapping(method=RequestMethod.POST,value="/upload/{jobID}")
    public Application upload(@RequestParam("file") MultipartFile file,@PathVariable String jobID,
            @RequestParam("name") String name,@RequestParam("emailId") String emailId,
            @RequestParam("applicationStatus") ApplicationStatus applicationStatus) throws IOException {

        Offer offer=offerRepository.findById(jobID).get();
        Application application=new Application();
        System.out.println(file.getContentType());
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        application.setApplicationStatus(ApplicationStatus.valueOf("APPLIED"));
        application.setResume(file.getBytes());
        application.getMykey().setOffer(offer);


        return applicationRepository.save(application); 
    }

and here is the detailed error

{
    "timestamp": "2018-10-15T17:31:31.346+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "No message available",
    "path": "/api/upload/SE"
}
Aditya
  • 950
  • 8
  • 37
  • look at this https://stackoverflow.com/questions/39037049/how-to-upload-a-file-and-json-data-in-postman – want2learn Oct 15 '18 at 18:27
  • Your methods seems correctly called so something issue in processing so check offer is coming from db or application.getMykey() is coming correctly or save method.. – kj007 Oct 16 '18 at 03:09

1 Answers1

0

try to use POJO as requestParams to more organize method input see http://dolszewski.com/spring/how-to-bind-requestparam-to-object/

and before getting optional test if present if(optional.isPresent()) then optional.get()