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

时间:2017-03-15 10:49:22

标签: java froala

使用Froala java sdk的Uplaod图像不起作用,出现此错误:

  

java.lang.Exception:Fieldname不正确。它必须是: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)

我将此文件作为Multipart。

那么为什么请求没有Part而requestBody有一个?

告诉我它是否不清楚:D

1 个答案:

答案 0 :(得分:0)

我发现了另一种方法可以使它与froala SDK中的示例源一起使用,但我必须在froala SDK文件中进行一些更改:

Froala Editor Java sdk Examples don't work