My client upload method:
public static void addPhoto(File photo) throws ParseException, IOException, InterruptedException {
HttpClient client = HttpClient.newBuilder().build();
HttpRequest request = HttpRequest.newBuilder()
.header("Content-Type","image/jpg")
.uri(URI.create(baseUrl + "data/addPhoto?date=4&category=temp&jwt="+jwt))
.PUT(HttpRequest.BodyPublishers.ofFile(photo.toPath()))
.build();
client.send(request, HttpResponse.BodyHandlers.ofString());
}
My Spring Boot method that receives the file:
@PutMapping(path = "/addPhoto")
public @ResponseBody
boolean addPhoto(@RequestParam(name = "jwt") String jwt,
@RequestParam("file") MultipartFile file,
@RequestParam(name = "date") long date,
@RequestParam(name = "category") String category) {
return crudService.addPhoto(jwt, date, file, category);
}
The current error:
2020-09-17 16:29:02.313 ERROR 8636 --- [nio-5000-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Current request is not a multipart request] with root cause
What kind of headers can I add to ensure my Spring Boot server receives the file without errors?