Am looking for sample code on pre ZuulFilter which can intercept the file upload request and replace the uploaded file with another file.

Tried by creating the HttpServletRequestWrapper but its not working.

   File file = new File("test.pdf");
   byte[] newFileBytes= FileUtils.readFileToByteArray(file);
     context.setRequest(new HttpServletRequestWrapper(httpServletRequest) {
            @Override
            public ServletInputStream getInputStream() throws IOException {
                return new ServletInputStreamWrapper(newFileBytes);
            }
            @Override
            public int getContentLength() {
                return newFileBytes.length;
            }
            @Override
            public long getContentLengthLong() {
                return newFileBytes.length;
            }
            @Override
            public BufferedReader getReader() throws IOException {
                return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(newFileBytes.getBytes("UTF-8"))));
            }
            @Override
            public byte[] getContentData() {
                return newFileBytes;
            }
        });

I Have seen some samplezuulfilters here , but it did not have the one am looking for https://github.com/spring-cloud-samples/sample-zuul-filters/tree/master/src/main/java/org/springframework/cloud/samplezuulfilters

Comment From: Omkarv29

@spencergibb Can you please help me on this.

Comment From: Omkarv29

Getting the below error.

Possibly unhandled rejection: {"data":{"timestamp":1615916530151,"status":400,"error":"Bad Request","exception":"org.springframework.web.multipart.support.MissingServletRequestPartException","message":"Required request part 'file' is not present",

Comment From: OlgaMaciaszek

Hello, @Omkarv29. It seems the file you're trying to upload is not available. Please provide a minimal, complete, verifiable example that reproduces the issue.

Comment From: spring-cloud-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-cloud-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.