Streaming dynamic files from Spring MVC

I have a Spring Web MVC application (as well as a BlazeDS application, although not appropriate), where files are dynamically generated based on specific client actions.

I would just like to map a specific directory in the file system to the URL of Spring MVC (or the application server) and let it serve the files in that directory (with streaming support and standard latest header update). Ideally, the mapped directory will be configured through the Spring configuration, since I already have support for each machine to configure it.

So how can I do this? The best I can find so far is to write a controller that reads the file manually and the byte count. However, this seems much less ideal. Does something like that already baked in Spring MVC or the standard specification of the application server support?

Thank!

+3
source share
3 answers

If your processing model supports it, why not completely disable the file system broker and completely transfer the file streams through the response stream as they are created? Take a look at the AbstractExcelView and AbstractPDFView Spring MVC classes to see some examples of how this is done.

+1
source

?

, . , , Tomcat -targeted . , , Context /path/to/your/resources /conf/server.xml:

<Context docBase="/path/to/your/resources" path="/resources" />

, http://example.com/resources/...

+1

- , nginx lighthttpd. .

, . , nginx X-Accel-Redirect. ( http-)

0

Source: https://habr.com/ru/post/1734805/


All Articles