Erro 413 com arquivos acima de 1 MB - resolvido

Como consigo imprimir estes logs ?

A requisição não chega nem no endpoint, entendo que o cors não deixa.

Pelo que entendi as configurações para o spring 2.3.5, deve ser estas, no properties

spring.servlet.multipart.max-file-size=128MB
spring.servlet.multipart.max-request-size=128MB
1 curtida

Isso mesmo.

1 curtida

Fiz isto e

@Override
    public void doFilter(final ServletRequest req, final ServletResponse resp, final FilterChain chain) throws IOException, ServletException {
        final HttpServletResponse response = (HttpServletResponse) resp;
        final HttpServletRequest request = (HttpServletRequest) req;
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
        response.setHeader("Access-Control-Expose-Headers", "Location");
        for (final Enumeration<?> e = request.getHeaderNames(); e.hasMoreElements();) {
            final String nextHeaderName = (String) e.nextElement();
            final String headerValue = request.getHeader(nextHeaderName);
            log.info("nextHeaderName: " + nextHeaderName);
            log.info("headerValue: " + headerValue);
        }
        if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            chain.doFilter(req, response);
        }
    }

no log apareceu isto:

2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: x-forwarded-for
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: 191.185.125.215
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: host
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: xxxxxx
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: connection
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: close
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: content-length
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: 228438
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: sec-ch-ua
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: accept
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: application/json, text/plain, */*
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: content-type
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: multipart/form-data; boundary=----WebKitFormBoundaryBG5jKKXk4qGIDqYQ
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: authorization
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: bearer 9e02166b-5c74-45ec-83be-9b4004029f75
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: sec-ch-ua-mobile
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: ?0
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: user-agent
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: sec-ch-ua-platform
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: "Windows"
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: origin
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: 
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: sec-fetch-site
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: same-site
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: sec-fetch-mode
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: cors
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: sec-fetch-dest
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: empty
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: referer
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: https://app.movimentoneem.life/
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: accept-encoding
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: gzip, deflate, br
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				nextHeaderName: accept-language
2021-12-13 09:38:37 [http-nio-9103-exec-1] INFO  - b.c.g.g.crud.config.SmpleCORSFilter -
				headerValue: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,fr;q=0.6

Quando o arquivo é maior que 1 Mega, não chega no servidor nem no cors, poir não imprimi log

spring.servlet.multipart.max-file-size = 1MB # Tamanho máximo do arquivo. Os valores podem usar os sufixos “MB” ou “KB” para indicar megabytes ou kilobytes, respectivamente.

spring.servlet.multipart.max-request-size = 10MB # Tamanho máximo da solicitação. Os valores podem usar os sufixos “MB” ou “KB” para indicar megabytes ou kilobytes, respectivamente.

Estou achando bem estranho isso, de não estar funcionando

Rapaiz, deve ter alguma camada em produção que está barrando requisições grandes, como um proxy, por exemplo.

1 curtida

Estou olhando com a infra

1 curtida

Você usa Nginx como Load Balancer/Reverse Proxy/etc ?

Se sim, por default o tamanho maximo de um arquivo importado é de 1MB.

Syntax: client_max_body_size size;
Default: client_max_body_size 1m;
Context: http, server, location
Sets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

Documentação Nginx - Module ngx_http_core_module

1 curtida

Vendo com a pessoa da infra

1 curtida