Skip to content

MultipartFile parameter must not be added as template variable #1776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
reda-alaoui opened this issue May 9, 2022 · 3 comments
Closed

MultipartFile parameter must not be added as template variable #1776

reda-alaoui opened this issue May 9, 2022 · 3 comments
Assignees
Labels
in: core Core parts of the project type: bug
Milestone

Comments

@reda-alaoui
Copy link
Contributor

reda-alaoui commented May 9, 2022

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.

@odrotbohm
Copy link
Member

Good catch! Thanks for the PR, too. 1.3 is unfortunately out of maintenance. Could you upgrade to a more recent 1.4.x?

@reda-alaoui
Copy link
Contributor Author

reda-alaoui commented May 10, 2022

We were already using a fork of 1.3.4 containing #1312 . I added #1777 to our fork.
So it's ok for us if it is only merged on 1.4.x.

But it would be really nice if someone could take a look at #1312 😊 🙏

@odrotbohm odrotbohm changed the title HAL Forms template does not support MultipartFile parameter MultipartFile parameter must not be added as template variable May 10, 2022
@odrotbohm odrotbohm self-assigned this May 10, 2022
@odrotbohm odrotbohm added this to the 1.4.3 milestone May 10, 2022
@odrotbohm odrotbohm added type: bug in: core Core parts of the project labels May 10, 2022
@odrotbohm odrotbohm modified the milestones: 1.4.3, 2.0 M3 May 10, 2022
@odrotbohm
Copy link
Member

I've merged and back-ported this into 1.5 and 1.4. I've slightly tweaked the implementation to also skip the MultipartFile instances even if non-null values are handed into the dummy method invocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants