本文介绍了作为分段文件上传时是否有最大文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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文件上传到我的rest控制器的方式.有没有可以上传的最大文件大小,或者有什么方法可以定义此类上传的最大文件大小.我在Vaadin客户端使用此代码.

This is how I upload the file as a Multipart file to my rest controller. Is there a max file size that can be uploaded or is there any way that I can define a max file size foe this kind of uploading. I use this code in my Vaadin client side.

推荐答案

在您的配置中尝试以下操作:

Try this in your config:

@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配置环境变量.或者只是放值.

I assume that env is Spring configuration environment variables.Or just put values instead.

这篇关于作为分段文件上传时是否有最大文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 01:13
查看更多