Skip to content

MultipartFile parameter must not be added as template variable #1776

@reda-alaoui

Description

@reda-alaoui

I use Spring HATEOAS 1.3.4.

Given:

@Controller
@RequestMapping("/foo")
public class MyController {
    
    @GetMapping
    public ResponseEntity<?> get() {
       return ResponseEntity.ok(
         new RepresentationModel<>(
           linkTo(methodOn(MyController.class).get())
             .withSelfRel()
             .andAffordance(afford(methodOn(MyController.class).uploadFile(null)))
         )
       );
    }

    @PostMapping(value = "/file", consumes = "multipart/form-data")
    public ResponseEntity<?> uploadFile(@RequestParam("file") MultipartFile file) {
      return ResponseEntity.noContent().build();
    }

}

Performing:

GET http://localhost:8080/foo/

Produces:

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/api/foo"
    }
  },
  "_templates": {
    "default": {
      "method": "put",
      "contentType": "multipart/form-data",
      "properties": [],
      "target": "http://localhost:8080/api/foo/file?file={file}"
    }
  }
}

As you can see, the target property is not valid because of file parameter.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions