0
  HttpPost post = new HttpPost(properties.getPropert("system.api.url"));
            post.setHeader("Accept", "application/json");
            MultipartEntity entity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            entity.addPart("file", new FileBody(file, event.getMIMEType()));
            post.setEntity(entity);  

这就是我将文件作为 Multipart 文件上传到我的休息控制器的方式。是否有可以上传的最大文件大小,或者有什么方法可以定义这种上传的最大文件大小。我在我的 Vaadin 客户端使用此代码。

4

1 回答 1

0

在你的配置中试试这个:

@Bean
public MultipartResolver multipartResolver() {
    return new StandardServletMultipartResolver();
}

@Bean
MultipartConfigElement multipartConfigElement() {
    MultiPartConfigFactory factory = new MultiPartConfigFactory();
    factory.setMaxFileSize(env.getRequiredProperty("MAX.FILE.SIZE"));
    factory.setMaxRequestSize(env.getRequiredProperty("MAX.FILES.SIZE"));
    factory.setFileSizeThreshold(env.getRequiredProperty("MAX.MEMORY.SIZE"));
    factory.setLocation(env.getRequiredProperty("IMAGE.PROCESSOR.UPLOADTMP"));

    return factory.createMultipartConfig();
}

我假设 env 是 Spring 配置环境变量。或者只是输入值。

于 2014-04-18T18:27:48.223 回答