[BUG] MultipartFile mapping issue with Spring Boot 3 and binary media types
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- aws, java, spring-boot
Línea de trabajo
Comienza con la configuración mostrada de LambdaHandler y StageAwareAwsProxyHttpServletRequestReader y, a continuación, sigue cómo aws-serverless-java-container-springboot3 pasa la solicitud multipart y el tipo de contenido image/jpeg a Spring Boot. Reproduce la carga de API Gateway/Lambda y verifica que el controlador vincula la imagen a MultipartFile sin devolver un error 415.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description:
I am encountering an issue when trying to upload images from my client to a Spring Boot 3 application deployed as a Lambda function using aws-serverless-java-container-springboot3.
Problem:
Despite configuring API Gateway with multipart/form-data as a binary media type, and observing the binary data successfully reaching the Lambda handler, the Spring controller fails to map the incoming request to a MultipartFile argument. Instead, a GlobalException is triggered with the message:
415 UNSUPPORTED_MEDIA_TYPE "Content type 'image/jpeg' not supported for bodyType=org.springframework.web.multipart.MultipartFile"
Setup:
Framework: Spring Boot 3
Serverless Java Container Dependency:
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-springboot3</artifactId>
<version>2.1.4</version>
</dependency>
LambdaHandler:
package net.myApp.lambda.handler;
import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.AsyncInitializationWrapper;
import com.amazonaws.serverless.proxy.AwsProxyExceptionHandler;
import com.amazonaws.serverless.proxy.AwsProxySecurityContextWriter;
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletResponseWriter;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler;
import com.amazonaws.serverless.proxy.spring.SpringBootProxyHandlerBuilder;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import jakarta.ws.rs.core.MediaType;
import net.myApp.lambda.StageAwareAwsProxyHttpServletRequestReader;
import net.myApp.rest.MyApp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
public class LambdaHandler implements RequestStreamHandler {
private static final Logger logger = LoggerFactory.getLogger(LambdaHandler.class);
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
handler =
new SpringBootProxyHandlerBuilder<AwsProxyRequest>()
.initializationWrapper(new AsyncInitializationWrapper())
.requestReader(new StageAwareAwsProxyHttpServletRequestReader())
.responseWriter(new AwsProxyHttpServletResponseWriter())
.securityContextWriter(new AwsProxySecurityContextWriter())
.exceptionHandler(new AwsProxyExceptionHandler())
.requestTypeClass(AwsProxyRequest.class)
.responseTypeClass(AwsProxyResponse.class)
.springBootApplication(MyApp.class)
.buildAndInitialize();
handler.getContainerConfig().addBinaryContentTypes(MediaType.MULTIPART_FORM_DATA, "image/jpeg", "image/png", "image/jpg");
} catch (ContainerInitializationException e) {
logger.error("FATAL: Failed to initialize Spring Boot application container. This will cause cold starts.", e);
throw new RuntimeException("Could not initialize Spring Boot application", e);
}
}
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
try {
handler.proxyStream(input, output, context);
} catch (Exception ex) {
logger.error("Error processing Lambda request: {}", ex.getMessage());
throw ex;
}
}
}
API Gateway Configuration: multipart/form-data has been added to the "Binary Media Types" in the API Gateway settings.
Steps Taken (and observations):
Client-side upload: Attempting to upload an image/jpeg file from the client.
API Gateway: Configured multipart/form-data as a binary media type.
Lambda Handler: Logs within the Lambda handler confirm that the binary data is indeed present and being received by the Lambda function.
Spring Controller: The request does not successfully map to a MultipartFile parameter in my Spring controller. Error: The GlobalException handler in my Spring application catches a 415 UNSUPPORTED_MEDIA_TYPE error, specifically stating that image/jpeg is not supported for MultipartFile.
Expected Behavior:
The aws-serverless-java-container should correctly handle the multipart/form-data request, allowing Spring Boot to bind the uploaded file to a MultipartFile object in the controller method.
Actual Behavior:
The request fails with a 415 UNSUPPORTED_MEDIA_TYPE error, indicating that the image/jpeg content type is not being correctly processed for MultipartFile binding within the Spring application, despite the data reaching the Lambda handler as binary.
Possible Cause/Request for Help:
It appears there might be an issue with how aws-serverless-java-container-springboot3 (version 2.1.4) or its underlying dependencies are processing multipart/form-data requests, preventing Spring's MultipartFile resolver from recognizing the incoming binary data as a valid file upload.
Any guidance or a fix for this issue would be greatly appreciated.
- Lenguaje dominante
- Java
- Estrellas
- 1.6k
- Forks
- 575
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 12
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de aws/serverless-java-container
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
aws/serverless-java-container#1729 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
aws/serverless-java-container#1715 ·
Los mantenedores suelen responder en 1 día
-
Support for API Gateway mTLS clientCert fieldPosiblemente ocupada @2748109647 la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 48/100
aws/serverless-java-container#1726 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
aws/serverless-java-container#1579 · 3 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
aws/serverless-java-container#1568 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de aws/serverless-java-container
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
ls1intum/thesis-management#1473 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
LunaDeerMC/Dominion#301 · 1 comentario ·
-
[FEATURE] Expose external refresh, node-level translog and warmer statsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertountriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
opensearch-project/opensearch-prometheus-exporter#680 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100