Cześć,
Pierwszy raz robię coś takiego, więc możliwe że robię jakąś głupotę. Chciałbym przesłać przy pomocy POST'a plik i tekst używając jednego requesta z poziomu HTML. Jak próbuję z samym plikiem to działa dobrze i plik się uploaduje, jak dodam tekst to już nie działa. Jest problem z odbiorem danych przez controller.
HTML wygląda tak:
<form method="POST" enctype="multipart/form-data" action="/">
<table width="100%" height="" style="border: 1px solid black; width:100%; text-align: left;padding: 5px; table-layout:fixed">>
<thead>
<tr>
<tr><th>DODAWNIE RECEPTURY</th></tr>
<th><input id= "stylreceptura" type="text" name="stylrecepturatext" placeholder="Wpisz styl piwa"></th>
<th>
<h2 th:text="${message}"/>
<td>Dodaj plik:<input type="file" name="file" /></td>
<ul>
<li th:each="file : ${files}">
<a th:href="${file}" th:text="${file}" />
</li>
</ul>
</th>
<th><button id="buttonDodajRec" type="submit" onclick="window.location.href=window.location.href">Dodaj recepturę</button></th>
<tr style="height: 60px"></tr>
</tr>
</thead>
</table>
</form>
A w CONTROLLERZE ODBIERAM TO TAK:
@PostMapping("/")
public String handleFileUpload(@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes, @RequestBody @Valid String stylreceptura) {
storageService.store(file);
redirectAttributes.addFlashAttribute("message",
"You successfully uploaded " + file.getOriginalFilename() + "!");
logger.info("DODAWANIE RECEPTURY FILEUPLOADCONTROLLER!!!!!!!!!!!!!!!");
logger.info(stylreceptura);
//return "redirect:/";
return "receptury";
}
Jak to przesłać, żeby np. w loggerze wylogować tekst z pola "stylreceptura"? Próbowałem też RequestParam, ale to chyba jednak nie tędy droga.