Downloading large files with Zuul
I am facing the problem of downloading large files via zuul. I am using apache-commons file upload ( https://commons.apache.org/proper/commons-fileupload/ ) to stream large files and also use zuul on the front. In my Spring Boot application, I have disabled the boot provided by Spring to use the application from Apache Commons:
spring:
http:
multipart:
enabled: false
The controller looks like this:
public ResponseEntity insertFile(@PathVariable Long profileId,
HttpServletRequest request) throws Exception {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator uploadItemIterator = upload.getItemIterator(request);
if (!uploadItemIterator.hasNext()) {
throw new FileUploadException("FileItemIterator was empty");
}
while (uploadItemIterator.hasNext()) {
FileItemStream fileItemStream = uploadItemIterator.next();
if (fileItemStream.isFormField()) {
continue;
}
//do stuff
}
return new ResponseEntity(HttpStatus.OK);
}
If I access my app directly (without zuul) the file upload works as intended. However, if accessed through zuul, the FileItemIterator has no items to traverse and the request immediately fails (ERR_CONNECTION_RESET). For zuul, I also disabled the multipart given by Spring. Otherwise it works. However, files are not streamed. They are fully loaded and only after I get inside the controller (normal Spring behavior). Is there a way to use apache-commons streaming options with zuul?
source to share
I found a solution. This is mainly described here:
http://cloud.spring.io/spring-cloud-static/spring-cloud.html#_uploading_files_through_zuul
What have I done to get it to work. Just step by step:
- To get around the Spring DispatcherServlet, I changed the url:
C: http: // localhost: 8081 / MyService / file
To: http: // localhost: 8081 / zuul / MyService / file
-
Stored disable Spring multipart upload:
spring: http: multipart: enabled: false
The following heading is not required. Transfer-encoding: chunked
I tried uploading a large file without it and everything was fine.
source to share
using / zuul when doing file upload based on this documentation https://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/2.0.2.RELEASE/multi/multi__router_and_filter_zuul.html#_uploading_files_through_zuul works, However, is there a way not to use this without forcing the client to have the / zuul prefix in the url?
source to share