Search in sources :

Example 1 with MultipartConfiguration

use of cn.taketoday.web.multipart.MultipartConfiguration in project today-framework by TAKETODAY.

the class LightRequestContext method getRequestParts.

/**
 * @throws FileSizeExceededException
 */
private List<RequestPart> getRequestParts() {
    if (requestParts == null) {
        try {
            final long contentLength = getContentLength();
            final LightHttpConfig config = this.config;
            final MultipartConfiguration multipartConfig = config.getMultipartConfig();
            if (contentLength > multipartConfig.getMaxRequestSize().toBytes()) {
                throw new FileSizeExceededException(multipartConfig.getMaxRequestSize(), null).setActual(DataSize.ofBytes(contentLength));
            }
            final MultipartIterator multipartIterator = new MultipartIterator(request);
            final MultipartInputStream inputStream = multipartIterator.getInputStream();
            final ArrayList<RequestPart> parts = new ArrayList<>();
            while (multipartIterator.hasNext(inputStream)) {
                parts.add(multipartIterator.obtainNext(config, multipartConfig));
            }
            requestParts = parts;
        } catch (IOException e) {
            throw new MultipartException("multipart read failed", e);
        }
    }
    return requestParts;
}
Also used : MultipartConfiguration(cn.taketoday.web.multipart.MultipartConfiguration) MultipartException(cn.taketoday.web.bind.MultipartException) FileSizeExceededException(cn.taketoday.http.FileSizeExceededException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with MultipartConfiguration

use of cn.taketoday.web.multipart.MultipartConfiguration in project today-framework by TAKETODAY.

the class WebApplicationLoader method configureParameterResolving.

/**
 * Configure {@link ParameterResolvingStrategy}s to resolve handler method arguments
 *
 * @param customizedStrategies Resolvers registry
 * @param mvcConfiguration All {@link WebMvcConfiguration} object
 */
protected void configureParameterResolving(List<ParameterResolvingStrategy> customizedStrategies, WebMvcConfiguration mvcConfiguration) {
    WebApplicationContext context = obtainApplicationContext();
    ParameterResolvingRegistry registry = context.getBean(ParameterResolvingRegistry.class);
    Assert.state(registry != null, "No ParameterResolvingRegistry in context");
    // user customize multipartConfig
    MultipartConfiguration multipartConfig = context.getBean(MultipartConfiguration.class);
    mvcConfiguration.configureMultipart(multipartConfig);
    // User customize parameter resolver
    // ------------------------------------------
    // user configure
    mvcConfiguration.configureParameterResolving(registry, customizedStrategies);
    registry.getCustomizedStrategies().add(customizedStrategies);
}
Also used : MultipartConfiguration(cn.taketoday.web.multipart.MultipartConfiguration) ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry) WebApplicationContext(cn.taketoday.web.WebApplicationContext)

Example 3 with MultipartConfiguration

use of cn.taketoday.web.multipart.MultipartConfiguration in project today-framework by TAKETODAY.

the class DispatcherServletInitializer method configureMultipart.

@Override
protected void configureMultipart(Dynamic registration) {
    MultipartConfigElement multipartConfig = getMultipartConfig();
    if (multipartConfig == null) {
        MultipartConfiguration configuration = getApplicationContext().getBean(MultipartConfiguration.class);
        if (configuration != null) {
            multipartConfig = new MultipartConfigElement(configuration.getLocation(), configuration.getMaxFileSize().toBytes(), configuration.getMaxRequestSize().toBytes(), (int) configuration.getFileSizeThreshold().toBytes());
            log.info("configure dispatcher-servlet multipart: {}", configuration);
        }
    }
    setMultipartConfig(multipartConfig);
    super.configureMultipart(registration);
}
Also used : MultipartConfigElement(jakarta.servlet.MultipartConfigElement) MultipartConfiguration(cn.taketoday.web.multipart.MultipartConfiguration)

Aggregations

MultipartConfiguration (cn.taketoday.web.multipart.MultipartConfiguration)3 FileSizeExceededException (cn.taketoday.http.FileSizeExceededException)1 WebApplicationContext (cn.taketoday.web.WebApplicationContext)1 MultipartException (cn.taketoday.web.bind.MultipartException)1 ParameterResolvingRegistry (cn.taketoday.web.bind.resolver.ParameterResolvingRegistry)1 MultipartConfigElement (jakarta.servlet.MultipartConfigElement)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1