Froala Java SDK:上传图片不起作用

Froala Java SDK: Upload Image doesn't work

使用 Froala java SDK 上传图片无效,出现此错误:

java.lang.Exception: Fieldname is not correct. It must be: file

我正在使用 spring 框架。这是我的代码:

@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();
        }
    }
}

我在 web.xml 中配置了 MultiPart:

<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>

并且在spring-context.xml:

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        </bean>

所以我用

检查了 HttpServletRequest
request.getParts() = []

但是当我输入参数时

public void enregistrerImage(@RequestBody Multipart file, HttpServletRequest request, HttpServletResponse response)

我有这个文件作为多部分。

那么为什么请求有 none 部分而 requestBody 有一个?

如果不清楚请告诉我:D

好吧,我找到了另一种方法来使其与 froala SDK 中的示例源一起工作,但我必须在 froala SDK 文件中进行一些更改: