首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Spring提供音频文件

使用Spring提供音频文件
EN

Stack Overflow用户
提问于 2016-06-27 02:11:27
回答 1查看 2K关注 0票数 0

是否有更有效的方式为音频文件与SpringBoot服务?

代码语言:javascript
复制
@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()
}

我每隔一段时间都会遇到这个错误:

代码语言:javascript
复制
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]

尽管我正在本地机器上进行测试,从一个角度应用程序发出的HTTP请求并不能立即下载该文件(速度为200‘t/s)。但是,如果我使用curl或者从地址栏下载它,它确实会立即被下载。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-15 11:16:33

问题是,我与其他资源(GET,POST)在同一个线程中提供音频文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38044992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档