【发布时间】:2015-09-27 20:44:28
【问题描述】:
我是 Servlet 和 Spring 框架的新手。 我尝试通过 Rest Service 从目录中获取媒体文件。
对于视频/mp4,我找不到任何东西。
对于音频,我这样做了: Writing mp3 file to response output stream
对于图片我这样做了:
@RequestMapping("/tmp/{uuid}")
@ResponseBody
public ResponseEntity<InputStreamResource> getTmp(@PathVariable("uuid") String uuid)
throws IOException {
Path path = Paths.get("/media/psmaster/HDD/TUC-IPS/" + uuid);
String contentType = Files.probeContentType(path);
FileSystemResource file = new FileSystemResource("/media/psmaster/HDD/TUC-IPS/" + uuid);
return ResponseEntity
.ok()
.contentLength(file.contentLength())
.contentType(
MediaType.parseMediaType(contentType))
.body(new InputStreamResource(file.getInputStream()));
}
有人可以帮忙解决问题吗?
【问题讨论】:
-
如果可能的话,我想通过一个 Rest Service 获取任何类型的文件。
-
“问题”?你什么都没提。
-
org.apache.catalina.connector.ClientAbortException: java.io.IOException: org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:393) 在 org.apache 的管道损坏。 tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:426) 在 org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:342) 在 org.apache.catalina.connector.OutputBuffer.close(OutputBuffer. java:295) 在 org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:...
-
我不知道到底是什么问题。
-
直接在问题中包含所有相关信息(使用编辑按钮),而不是在 cmets 中。
ClientAbortException暗示数据的消费者是罪魁祸首;关于这个特殊例外有很多问题,请使用顶部的搜索栏。
标签: spring file spring-boot mp4 outputstream