Uplaod image with Froala java sdk doesn't work, got this error:
java.lang.Exception: Fieldname is not correct. It must be: file
I'm using spring framework. This is my code:
@RestController
public class SoutienController {
@RequestMapping(value = "/enregistrerImage", method = RequestMethod.POST)
public void enregistrerImage(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Map<Object, Object> responseData;
ImageOptions options = new ImageOptions();
options.setFieldname("file");
try {
String fileRoute = "/images/";
responseData = Image.upload(request, fileRoute, options);
System.out.println("OK");
} catch (Exception e) {
e.printStackTrace();
responseData = new HashMap<Object, Object>();
responseData.put("error", e.toString());
}
String jsonResponseData = new Gson().toJson(responseData);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
try {
response.getWriter().write(jsonResponseData);
} catch (IOException e) {
e.printStackTrace();
}
}
}
I configure MultiPart in web.xml:
<multipart-config>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
And in spring-context.xml:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
So I checked the HttpServletRequest with
request.getParts() = []
But when I put in parameter
public void enregistrerImage(@RequestBody Multipart file, HttpServletRequest request, HttpServletResponse response)
I have this file as Multipart.
So why the request have none Part while the requestBody have one ?
Tell me if it's not clear :D
Well I found another way to make it works with the source of Examples in froala SDK, but I have to make some changes in the froala SDK files: