0

I have a Controller like this:

@RequestMapping(value = "/user/", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody UserLesserDTO createUser(@RequestParam("profileImage") MultipartFile file, @RequestBody UserDTO user) {
    System.out.println("Creating User " + user.getName() );

    try {
        UserDTO userTest = userService.getUserByUsername( user.getName() );
        return new UserLesserDTO( userTest );
    } catch ( NoResultException e ) {
        //
    }
    return new UserLesserDTO( userService.addUser(user) );
}

and a form to create the user.

This form have a input type file named profileImage.

My question is: As I can't send a PUT method in HTML, I MUST send it as an Ajax request converting all form attributes to a JSON object and send it as PUT. But I need to send a file too and I don't know how to proceed.

Magno C
  • 1,922
  • 4
  • 28
  • 53
  • There is nothing called PUT in HTML and can't be. HTML is just a markup language and for communicating with the server you either use HTML form (that is treated specially) of JavaScript. [Here](https://stackoverflow.com/questions/2320069/jquery-ajax-file-upload) you can find some useful stuff of how to upload via AJAX. – ikos23 Jun 10 '18 at 03:27
  • Ok. I know I must to respect the purpose of the PUT and POST methods but I need (love) to keep things simple too. I just create `/user/create/` and `/user/update/` mappings both accepting `POST`. Please do not blame me for it. – Magno C Jun 10 '18 at 03:33
  • @john I'm not talking about PUT tag. I'm talking about PUT form method. – Magno C Jun 19 '18 at 14:28

0 Answers0