rest - 休息:如何流式传输视频(不下载)
问题描述
这是将视频下载到磁盘而不是流式传输视频(这是我想要的)的代码。
@GET
@Path("/articleVideo/{videoID}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getArticleVideo(@PathParam("videoID") int videoID) {
MediaDAO mediaDAO = new MediaDAO();
MediaEntity video = mediaDAO.getMediaById(videoID);
if(video == null) {
throw new WebApplicationException("Requested user not found");
}
File file = new File(video.getLink());
if (!file.exists()) {
throw new WebApplicationException(404);
}
StreamingOutput out = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
try {
InputStream input = new FileInputStream(file);
IOUtils.copy(input, output);
output.flush();
}
}
};
return Response.ok(out).build();
}
我尝试了很多组合,并在此处查找了许多其他有关堆栈溢出的帖子,但没有一个有效。
解决方案
推荐阅读
- ios - iOS 15 SDK - `memcpy()` 未导出
- regex - 正则表达式匹配多个条目
- java - 如何仅反转字符串中的数字
- firebase - 为什么当我的 TextFormField 获得焦点时我的页面会重新加载?
- mqtt - Twincat 3 中与 Microsoft Azure 云的 MQTT 连接
- flutter - 如何在 Flutter 中将音频与 lottie / rive 动画同步?
- php - laravel 队列中的 ShouldBeUnique 是什么
- pine-script - 当有 2 支蜡烛但少于 4 支时如何突出显示?
- html - ngxPrint 在内部组件的角度使用时无效
- python - 如何通过按单元格删除重复项将数字数据框的 ColA 转换为按每个单元格值排序?