文件的自定义进度条从application / octet-stream REST响应下载

时间:2018-02-03 15:29:13

标签: javascript java jquery angularjs rest

我需要通过调用生成Application / octet-stream的REST Api将文件下载到浏览器,文件大小约为1 GB,我需要在屏幕上显示自定义进度条,下载百分比(或至少简单下载inprogress图像,没有任何百分比)。

REST api代码(使用泽西):

@Component
@Path("/DOC")
public class DownloadDOCApi {
@GET
@Path("/download")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getArticleById() {
    Client client = ClientBuilder.newClient();
    String url = "http://localhost:6060/download";
    String fileName = "fileName.msi";
    final InputStream responseStream =         client.target(url).request().get(InputStream.class);

    System.out.println(responseStream.getClass());
    StreamingOutput output = new StreamingOutput() {
        @Override
        public void write(OutputStream out) throws IOException, WebApplicationException {  
            int length;
            byte[] buffer = new byte[1024];
            while((length = responseStream.read(buffer)) != -1) 
            {
                out.write(buffer, 0, length);
            }
            out.flush();
            responseStream.close();
        }};   
     return Response.ok(output).header("Content-Disposition", "attachment, filename="+fileName+"").header("Content-Length","249450496").build();
}

用于从前端调用REST API的URL: http://localhost:7070/DOC/download

我可以下载文件,而且我可以获得浏览器的默认进度条,但我仍然需要在屏幕上自定义进度条。

有人帮我实现自定义进度条或仅在屏幕上显示文件下载的进度图像。

0 个答案:

没有答案