Java server side sending file with resume support?

我的梦境 提交于 2019-11-27 02:58:49

问题


I am trying to allow my java server to transfer a file where a web browser can download.

However, I want the browser if they pause and resume the file transfer to work and not start the download all over again.

Anyone know java code for the server side to fix this issue?


回答1:


There are two parts to supporting resumable downloads:

  • Your response needs to return the Accept-Ranges and Content-Range headers
  • You need to write code that can then handle the HTTP Range headers and If-Range to know where a client needs to resume

If you're serving up a static resource your best bet is to use a proxy server, like Apache, to handle the download. If a proxy server isn't an option then you can probably find a Servlet that is bundled with your app server; for example, Tomcat has as DefaultServlet. The downside to this option is that it creates a hard dependency between your application and the application server, which may not be acceptable.

If you decide to roll your own I recommend taking a look at Apache's HTTP Components. It's a nice API that makes working with HTTP requests and responses much easier.




回答2:


David This link helps you to get started with the development of file download with resume support

http://www.webspheretools.com/sites/webspheretools.nsf/docs/Java%20download%20manager


来源:https://stackoverflow.com/questions/5011446/java-server-side-sending-file-with-resume-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!