使用SpringBoot提供音频文件是否更有效?
@RequestMapping(value = '/getSong/{id}', method = RequestMethod.GET)
def getMusic(HttpServletResponse response, @PathVariable Integer id) throws Exception {
Music m = shuffler.findTrackPathById(id)
if (m == null) {
return "File not found"
}
response.setContentType("audio/mpg")
response.setHeader("Content-disposition", "inline; filename=" + m.getFilename())
InputStream is = new FileInputStream(m.getFullpath())
FileCopyUtils.copy(is, response.getOutputStream())
response.getOutputStream().close()
}
我偶尔会遇到这个错误:
2016-06-26 08:47:16.460 INFO 10831 --- [ Thread-11] o.e.jetty.server.handler.ContextHandler : Stopped o.s.b.c.e.j.JettyEmbeddedWebAppContext@ea9e141{/,file:/private/var/folders/73/gwl8bs6s4hgcl6vyln6_wzsc0000gn/T/jetty-docbase.7966202443679651433.8080/,UNAVAILABLE}
2016-06-26 08:47:46.463 WARN 10831 --- [ Thread-11] o.e.jetty.util.thread.QueuedThreadPool : qtp1041326823{STOPPING,8<=8<=200,i=0,q=1} Couldn't stop Thread[qtp1041326823-19,5,main]
从Angular应用程序发出的HTTP请求不会立即下载文件(速度约为200Kb / s) - 即使我在本地计算机上进行测试。但是,如果我使用curl或从地址栏下载它,它会立即下载。
答案 0 :(得分:0)
问题是我在与其他资源(GET,POST)相同的线程中提供音频文件。