There is a task to pass file path as @PathVariable
in Spring MVC to REST Service with GET
request.
We can easily do it with POST
sending String of file path in JSON.
How we can do with GET
request and @Controller
like this?
@RequestMapping(value = "/getFile", method = RequestMethod.GET)
public File getFile(@PathVariable String path) {
// do something
}
Request:
GET /file/getFile/"/Users/user/someSourceFolder/8.jpeg"
Content-Type: application/json
You should define your controller like this:
@RequestMapping(value = "/getFile/{path:.+}", method = RequestMethod.GET)
public File getFile(@PathVariable String path) {
// do something
}
Ok. you use to get pattern. sending get pattern url.
Use @RequestParam.
@RequestMapping(value = "/getFile", method = RequestMethod.GET)
public File getFile(@RequestParam("path") String path) {
// do something
}
and if you use @PathVariable.
@RequestMapping(value = "/getFile/{path}", method = RequestMethod.POST)
public File getFile(@PathVariable String path) {
// do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With