You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two services gateway and myfunction services.
I am uploading image using angular js.
But when request routing to myfunction services the Image file get removed from request.
I have used customer filter to in both gateway and myfunction sevrices to check if the request content image file or not.
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.Part;
@Component
public class CustomFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE);
Object parameterValue = request.getParameter("file");
if(contentType!=null && request.getContentType().startsWith(MediaType.MULTIPART_FORM_DATA_VALUE)) {
Collection<Part> parts = request.getParts();
for (Part part : parts) {
// Check if the part is a file or a form field
if (part.getContentType() != null) {
// File part
System.out.println("File part name: " + part.getName());
System.out.println("File name: " + part.getSubmittedFileName());
// You can process the file here
} else {
// Form field part
System.out.println("Form field name: " + part.getName());
// You can process the form field here
}
}
}
// Check if the request contains a file
boolean hasFile = request.getContentType() != null && request.getContentType().startsWith(MediaType.MULTIPART_FORM_DATA_VALUE);
Map<String, String[]> parameterMap = request.getParameterMap();
for (String paramName : parameterMap.keySet()) {
Object paramValues = parameterMap.get(paramName);
System.out.println("manoj" +paramName);
// for (String paramValue : paramValues) {
// System.out.println("Parameter: " + paramName + ", Value: " + paramValue);
}
// Perform your validations based on file presence, content type, and parameter value
// if (hasFile && contentType != null && contentType.equals(MediaType.APPLICATION_JSON_VALUE) && parameterValue != null) {
// Proceed with the request
filterChain.doFilter(request, response);
// } else {
// Reject the request with a 400 Bad Request response
// response.setStatus(HttpStatus.BAD_REQUEST.value());
// response.getWriter().write("Invalid request parameters");
// return;
// }
}
}
I can see the file when request is in gateway but it get missed when it come to myfunction services.
I am using oauth2 client in gateway and ouath2 resources server in myfunction services.
please can you tell me what is worng with the gateway.
one more point to hightlight When I use postman It works fine the file did lost.
The text was updated successfully, but these errors were encountered:
Can you explain in detail..I did not get what you are explaing
I might be misunderstanding but it sounds like what Spencer is saying is that you're already reading the stream in your filter. Once the stream has been read it's not being sent to your controller.
I have two services gateway and myfunction services.
I am uploading image using angular js.
But when request routing to myfunction services the Image file get removed from request.
I have used customer filter to in both gateway and myfunction sevrices to check if the request content image file or not.
I can see the file when request is in gateway but it get missed when it come to myfunction services.
I am using oauth2 client in gateway and ouath2 resources server in myfunction services.
please can you tell me what is worng with the gateway.
one more point to hightlight When I use postman It works fine the file did lost.
The text was updated successfully, but these errors were encountered: