javax.servlet.MultipartConfigElement Java Examples

The following examples show how to use javax.servlet.MultipartConfigElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #2
Source File: JettyServer.java    From pippo with Apache License 2.0 6 votes vote down vote up
protected ServletContextHandler createPippoHandler() {
    MultipartConfigElement multipartConfig = createMultipartConfigElement();
    ServletContextHandler handler = new PippoHandler(ServletContextHandler.SESSIONS, multipartConfig);
    handler.setContextPath(getSettings().getContextPath());

    // inject application as context attribute
    handler.setAttribute(PIPPO_APPLICATION, getApplication());

    // add pippo filter
    addPippoFilter(handler);

    // add initializers
    handler.addEventListener(new PippoServletContextListener());

    // all listeners
    listeners.forEach(listener -> {
        try {
            handler.addEventListener(listener.newInstance());
        } catch (InstantiationException | IllegalAccessException e) {
            throw new PippoRuntimeException(e);
        }
    });

    return handler;
}
 
Example #3
Source File: TestUploadConfig.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void getMultipartConfig_default() {
  ArchaiusUtils.setProperty(RestConst.UPLOAD_DIR, "upload");

  UploadConfig uploadConfig = new UploadConfig();
  MultipartConfigElement multipartConfigElement = uploadConfig.toMultipartConfigElement();

  Assert.assertEquals("upload", uploadConfig.getLocation());
  Assert.assertEquals(-1L, uploadConfig.getMaxFileSize());
  Assert.assertEquals(-1L, uploadConfig.getMaxSize());
  Assert.assertEquals(0, uploadConfig.getFileSizeThreshold());

  Assert.assertEquals("upload", multipartConfigElement.getLocation());
  Assert.assertEquals(-1L, multipartConfigElement.getMaxFileSize());
  Assert.assertEquals(-1L, multipartConfigElement.getMaxRequestSize());
  Assert.assertEquals(0, multipartConfigElement.getFileSizeThreshold());
}
 
Example #4
Source File: TestUploadConfig.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void getMultipartConfig_config() {
  ArchaiusUtils.setProperty(RestConst.UPLOAD_DIR, "upload");
  ArchaiusUtils.setProperty(RestConst.UPLOAD_MAX_FILE_SIZE, 1);
  ArchaiusUtils.setProperty(RestConst.UPLOAD_MAX_SIZE, 2);
  ArchaiusUtils.setProperty(RestConst.UPLOAD_FILE_SIZE_THRESHOLD, 3);

  UploadConfig uploadConfig = new UploadConfig();
  MultipartConfigElement multipartConfigElement = uploadConfig.toMultipartConfigElement();

  Assert.assertEquals("upload", uploadConfig.getLocation());
  Assert.assertEquals(1, uploadConfig.getMaxFileSize());
  Assert.assertEquals(2, uploadConfig.getMaxSize());
  Assert.assertEquals(3, uploadConfig.getFileSizeThreshold());

  Assert.assertEquals("upload", multipartConfigElement.getLocation());
  Assert.assertEquals(1, multipartConfigElement.getMaxFileSize());
  Assert.assertEquals(2, multipartConfigElement.getMaxRequestSize());
  Assert.assertEquals(3, multipartConfigElement.getFileSizeThreshold());
}
 
Example #5
Source File: ServletUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
static void setServletParameters(ServletContext servletContext) {
  UploadConfig uploadConfig = new UploadConfig();
  MultipartConfigElement multipartConfig = uploadConfig.toMultipartConfigElement();
  if (multipartConfig == null) {
    return;
  }

  File dir = createUploadDir(servletContext, multipartConfig.getLocation());
  LOGGER.info("set uploads directory to \"{}\".", dir.getAbsolutePath());

  List<ServletRegistration> servlets = findServletRegistrations(servletContext, RestServlet.class);
  for (ServletRegistration servletRegistration : servlets) {
    if (!Dynamic.class.isInstance(servletRegistration)) {
      continue;
    }

    Dynamic dynamic = (Dynamic) servletRegistration;
    dynamic.setMultipartConfig(multipartConfig);
  }
}
 
Example #6
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #7
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #8
Source File: ProxyServletSetup.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
@Override
public void accept(final Context context) {
    final Configuration config = instance.getConfiguration().getExtension(Configuration.class);
    if (config.skip) {
        return;
    }
    context.addServletContainerInitializer((c, ctx) -> {
        final ServletRegistration.Dynamic servlet = ctx.addServlet("meecrowave-proxy-servlet", CDIProxyServlet.class);
        servlet.setLoadOnStartup(1);
        servlet.setAsyncSupported(true);
        servlet.addMapping(config.mapping);
        if (config.multipart) {
            servlet.setMultipartConfig(new MultipartConfigElement(
                    config.multipartLocation,
                    config.multipartMaxFileSize,
                    config.multipartMaxRequestSize,
                    config.multipartFileSizeThreshold));
        }
        servlet.setInitParameter("mapping", config.mapping);
        servlet.setInitParameter("configuration", config.configuration);
    }, null);
}
 
Example #9
Source File: TestStandardContext.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
Example #10
Source File: DispatcherServletInitializer.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public void start () throws ServletException, NamespaceException
{
    final BundleContext bundleContext = FrameworkUtil.getBundle ( DispatcherServletInitializer.class ).getBundleContext ();
    this.context = Dispatcher.createContext ( bundleContext );

    this.errorHandler = new ErrorHandlerTracker ();

    Dictionary<String, String> initparams = new Hashtable<> ();

    final MultipartConfigElement multipart = Servlets.createMultiPartConfiguration ( PROP_PREFIX_MP );
    final DispatcherServlet servlet = new DispatcherServlet ();
    servlet.setErrorHandler ( this.errorHandler );
    this.webContainer.registerServlet ( servlet, "dispatcher", new String[] { "/" }, initparams, 1, false, multipart, this.context );

    this.proxyFilter = new FilterTracker ( bundleContext );
    this.webContainer.registerFilter ( this.proxyFilter, new String[] { "/*" }, null, null, this.context );

    initparams = new Hashtable<> ();
    initparams.put ( "filter-mapping-dispatcher", "request" );
    this.webContainer.registerFilter ( new BundleFilter (), new String[] { "/bundle/*" }, null, initparams, this.context );

    this.jspTracker = new BundleTracker<> ( bundleContext, Bundle.INSTALLED | Bundle.ACTIVE, new JspBundleCustomizer ( this.webContainer, this.context ) );
    this.jspTracker.open ();
}
 
Example #11
Source File: AbstractWebApplicationInitializer.java    From bearchoke with Apache License 2.0 6 votes vote down vote up
protected void createSpringServlet(ServletContext servletContext) {
        log.info("Creating Spring Servlet started....");

        AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
        appContext.register(
                WebMvcConfig.class
        );

        DispatcherServlet sc = new DispatcherServlet(appContext);

        ServletRegistration.Dynamic appServlet = servletContext.addServlet("DispatcherServlet", sc);
        appServlet.setLoadOnStartup(1);
        appServlet.addMapping("/");

        // for serving up asynchronous events in tomcat
        appServlet.setInitParameter("dispatchOptionsRequest", "true");
        appServlet.setAsyncSupported(true);

        // enable multipart file upload support
        // file size limit is 10Mb
        // max file request size = 20Mb
        appServlet.setMultipartConfig(new MultipartConfigElement("/tmp", 10000000l, 20000000l, 0));

//        log.info("Creating Spring Servlet completed");
    }
 
Example #12
Source File: TestStandardContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMappingDecoded("/regular", "regular");
    context.addServletMappingDecoded("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
Example #13
Source File: TestServer.java    From webtau with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(String url, Request baseRequest, HttpServletRequest request,
                   HttpServletResponse response) throws IOException, ServletException {

    Map<String, TestServerResponse> responses = findResponses(request);

    MultipartConfigElement multipartConfigElement = new MultipartConfigElement((String) null);
    request.setAttribute(Request.MULTIPART_CONFIG_ELEMENT, multipartConfigElement);

    TestServerResponse testServerResponse = responses.get(baseRequest.getOriginalURI());
    if (testServerResponse == null) {
        response.setStatus(404);
    } else {
        testServerResponse.responseHeader(request).forEach(response::addHeader);

        byte[] responseBody = testServerResponse.responseBody(request);
        response.setStatus(testServerResponse.responseStatusCode());
        response.setContentType(testServerResponse.responseType(request));

        if (responseBody != null) {
            response.getOutputStream().write(responseBody);
        }
    }

    baseRequest.setHandled(true);
}
 
Example #14
Source File: Application.java    From clamav-rest with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Bean
MultipartConfigElement multipartConfigElement() {
  MultipartConfigFactory factory = new MultipartConfigFactory();
  factory.setMaxFileSize(maxfilesize);
  factory.setMaxRequestSize(maxrequestsize);
  return factory.createMultipartConfig();
}
 
Example #15
Source File: SolrRequestParsers.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public MultipartRequestParser(int uploadLimitKB) {
  multipartConfigElement = new MultipartConfigElement(
      null, // temp dir (null=default)
      -1, // maxFileSize  (-1=none)
      uploadLimitKB * 1024, // maxRequestSize
      100 * 1024 ); // fileSizeThreshold after which will go to disk
}
 
Example #16
Source File: RequestPartIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@BeforeClass
public static void startServer() throws Exception {
	// Let server pick its own random, available port.
	server = new Server(0);

	ServletContextHandler handler = new ServletContextHandler();
	handler.setContextPath("/");

	Class<?> config = CommonsMultipartResolverTestConfig.class;
	ServletHolder commonsResolverServlet = new ServletHolder(DispatcherServlet.class);
	commonsResolverServlet.setInitParameter("contextConfigLocation", config.getName());
	commonsResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
	handler.addServlet(commonsResolverServlet, "/commons-resolver/*");

	config = StandardMultipartResolverTestConfig.class;
	ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class);
	standardResolverServlet.setInitParameter("contextConfigLocation", config.getName());
	standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
	standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
	handler.addServlet(standardResolverServlet, "/standard-resolver/*");

	server.setHandler(handler);
	server.start();

	Connector[] connectors = server.getConnectors();
	NetworkConnector connector = (NetworkConnector) connectors[0];
	baseUrl = "http://localhost:" + connector.getLocalPort();
}
 
Example #17
Source File: MultipartConfiguration.java    From EasyEE with MIT License 5 votes vote down vote up
@Bean  
public MultipartConfigElement multipartConfigElement() {  
    MultipartConfigFactory factory = new MultipartConfigFactory();  
    long maxFileSize=524288000; //500MB
    long maxRequestSize=524288000; //500MB
    factory.setMaxFileSize(maxFileSize);
    factory.setMaxRequestSize(maxRequestSize);  
    return factory.createMultipartConfig();  
}
 
Example #18
Source File: WebMvcConfigurer.java    From mysiteforme with Apache License 2.0 5 votes vote down vote up
@Bean
public MultipartConfigElement multipartConfigElement() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    // 设置文件大小限制 ,超出设置页面会抛出异常信息,
    // 这样在文件上传的地方就需要进行异常信息的处理了;
    factory.setMaxFileSize("10MB"); // KB,MB
    /// 设置总上传数据总大小
    factory.setMaxRequestSize("50MB");
    // Sets the directory location where files will be stored.
    // factory.setLocation("路径地址");
    return factory.createMultipartConfig();
}
 
Example #19
Source File: MCRUploadServletDeployer.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private MultipartConfigElement getMultipartConfig() {
    String location = MCRConfiguration2.getStringOrThrow(MCR_FILE_UPLOAD_TEMP_STORAGE_PATH);
    long maxFileSize = MCRConfiguration2.getLong("MCR.FileUpload.MaxSize").orElse(5000000L);
    int fileSizeThreshold = MCRConfiguration2.getInt("MCR.FileUpload.MemoryThreshold").orElse(1000000);
    LogManager.getLogger()
        .info(() -> MCRUploadViaFormServlet.class.getSimpleName() + " accept files and requests up to "
            + maxFileSize + " bytes and uses " + location + " as tempory storage for files larger "
            + fileSizeThreshold + " bytes.");
    return new MultipartConfigElement(location, maxFileSize, maxFileSize,
        fileSizeThreshold);
}
 
Example #20
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void verifyMultipartServlet() {
    ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    MultipartConfigElement multipart = src.getServletPathMatch().getServletChain().getManagedServlet().getMultipartConfig();
    if(multipart == null) {
        throw UndertowServletMessages.MESSAGES.multipartConfigNotPresent();
    }
}
 
Example #21
Source File: Application.java    From Resource with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 文件上传配置
 *
 * @return
 */
@Bean
public MultipartConfigElement multipartConfigElement()
{
    MultipartConfigFactory factory = new MultipartConfigFactory();
    //文件最大
    factory.setMaxFileSize("10240KB"); //KB,MB
    /// 设置总上传数据总大小
    factory.setMaxRequestSize("102400KB");
    return factory.createMultipartConfig();
}
 
Example #22
Source File: UploadConfig.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public MultipartConfigElement toMultipartConfigElement() {
  String location = DynamicPropertyFactory.getInstance().getStringProperty(RestConst.UPLOAD_DIR, null).get();
  if (location == null) {
    LOGGER.info("{} is null, not support upload.", RestConst.UPLOAD_DIR);
    return null;
  }

  return new MultipartConfigElement(
      location,
      DynamicPropertyFactory.getInstance().getLongProperty(RestConst.UPLOAD_MAX_FILE_SIZE, -1L).get(),
      DynamicPropertyFactory.getInstance().getLongProperty(RestConst.UPLOAD_MAX_SIZE, -1L).get(),
      DynamicPropertyFactory.getInstance().getIntProperty(RestConst.UPLOAD_FILE_SIZE_THRESHOLD, 0).get());
}
 
Example #23
Source File: UndertowServer.java    From pippo with Apache License 2.0 5 votes vote down vote up
protected DeploymentManager createPippoDeploymentManager() {
    DeploymentInfo info = Servlets.deployment();
    info.setDeploymentName("Pippo");
    info.setClassLoader(this.getClass().getClassLoader());
    info.setContextPath(getSettings().getContextPath());
    info.setIgnoreFlush(true);

    // inject application as context attribute
    info.addServletContextAttribute(PIPPO_APPLICATION, getApplication());

    // add pippo filter
    addPippoFilter(info);

    // add initializers
    info.addListener(new ListenerInfo(PippoServletContextListener.class));

    // add listeners
    listeners.forEach(listener -> info.addListener(new ListenerInfo(listener)));

    ServletInfo defaultServlet = new ServletInfo("DefaultServlet", DefaultServlet.class);
    defaultServlet.addMapping("/");

    MultipartConfigElement multipartConfig = createMultipartConfigElement();
    defaultServlet.setMultipartConfig(multipartConfig);
    info.addServlets(defaultServlet);

    DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(info);
    deploymentManager.deploy();

    return deploymentManager;
}
 
Example #24
Source File: MultipartConfigure.java    From cms with Apache License 2.0 5 votes vote down vote up
/**
 * 文件上传临时路径
 */
@Bean
MultipartConfigElement multipartConfigElement() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    String location = properties.getLocationDirectory();
    File tmpFile = new File(location);
    if (!tmpFile.exists()) {
        tmpFile.mkdirs();
    }
    factory.setLocation(location);
    return factory.createMultipartConfig();
}
 
Example #25
Source File: WebConfig.java    From easyweb with Apache License 2.0 5 votes vote down vote up
@Bean
public MultipartConfigElement multipartConfigElement() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    // 设置文件大小限制 ,超出设置页面会抛出异常信息,
    // 这样在文件上传的地方就需要进行异常信息的处理了;
    factory.setMaxFileSize("1024KB"); // KB,MB
    /// 设置总上传数据总大小
    factory.setMaxRequestSize("2048KB");
    // Sets the directory location where files will be stored.
    // factory.setLocation("路径地址");
    return factory.createMultipartConfig();
}
 
Example #26
Source File: DefaultServletEnvironmentTest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test setMultipartConfig method.
 */
@Test
public void testMultipartConfig() {
    TestSnoopServlet servlet = new TestSnoopServlet();
    DefaultServletEnvironment environment = new DefaultServletEnvironment(null, null, servlet);
    assertNull(environment.getMultipartConfig());
    environment.setMultipartConfig(new MultipartConfigElement("/location"));
    assertNotNull(environment.getMultipartConfig());
}
 
Example #27
Source File: WebCampaign.java    From bidder with Apache License 2.0 5 votes vote down vote up
public String multiPart(Request baseRequest, HttpServletRequest request, MultipartConfigElement config)
		throws Exception {

	HttpSession session = request.getSession(false);
	String user = (String) session.getAttribute("user");

	baseRequest.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, config);
	Collection<Part> parts = request.getParts();
	for (Part part : parts) {
		System.out.println("" + part.getName());
	}

	Part filePart = request.getPart("file");

	InputStream imageStream = filePart.getInputStream();
	byte[] resultBuff = new byte[0];
	byte[] buff = new byte[1024];
	int k = -1;
	while ((k = imageStream.read(buff, 0, buff.length)) > -1) {
		byte[] tbuff = new byte[resultBuff.length + k]; // temp buffer size
														// = bytes already
														// read + bytes last
														// read
		System.arraycopy(resultBuff, 0, tbuff, 0, resultBuff.length); // copy
																		// previous
																		// bytes
		System.arraycopy(buff, 0, tbuff, resultBuff.length, k); // copy
																// current
																// lot
		resultBuff = tbuff; // call the temp buffer as your result buff
	}

	Map response = new HashMap();
	return getString(response);

}
 
Example #28
Source File: MultipartConfig.java    From FlyCms with MIT License 5 votes vote down vote up
@Bean
public MultipartConfigElement multipartConfigElement(){
    MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setMaxFileSize("10MB");
    factory.setMaxRequestSize("10MB");
    return factory.createMultipartConfig();
}
 
Example #29
Source File: WebMvcConfig.java    From mayday with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 文件上传配置
 * 
 * @return
 */
@Bean
public MultipartConfigElement multipartConfigElement() {
	MultipartConfigFactory factory = new MultipartConfigFactory();
	// 单个文件最大 KB,MB
	factory.setMaxFileSize("10240KB");
	/// 设置总上传数据总大小
	factory.setMaxRequestSize("102400KB");
	return factory.createMultipartConfig();
}
 
Example #30
Source File: MultipartConfig.java    From eladmin with Apache License 2.0 5 votes vote down vote up
/**
 * 文件上传临时路径
 */
@Bean
MultipartConfigElement multipartConfigElement() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    String location = System.getProperty("user.home") + "/.eladmin/file/tmp";
    File tmpFile = new File(location);
    if (!tmpFile.exists()) {
        if (!tmpFile.mkdirs()) {
            System.out.println("create was not successful.");
        }
    }
    factory.setLocation(location);
    return factory.createMultipartConfig();
}