java如何支持多块请求

cngwdvgl  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(202)

加载pdf文件时,我希望在获取部分数据后显示pdf,然后在显示新的pdf页面时要求后端获取数据。我在前端使用了插件,并多次使用块请求后端,但在后端我不知道如何编写代码。
前端代码

pdfui.openPDFByHttpRangeRequest({
    range: {
        url: getPDFURIByPdfIdURL + "?pdfId=" + pdfId,
        chunkSize: 10240
    }
})

后台代码

@GetMapping("/getPDFURIByPdfId")
public void getPDFURIByPdfId(HttpServletRequest request, HttpServletResponse response) {
    int pdfId = Integer.parseInt(request.getParameter("pdfId"));
    String filePath = foxitPDFViewService.getPdfurl(pdfId);
    response.setContentType("application/pdf");
    try {
        FileCopyUtils.copy(new FileInputStream(filePath), response.getOutputStream());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

我知道后端不能直接使用inputstream,我尝试使用 org.Apache.HTTP.Impl.IO.ChunkedInputStream ,但我不知道 SessionInputBuffer 如何创建 public ChunkedInputStream (final SessionInputBuffer in, final MessageConstraints constraints) {} 我认为后端应该使用 chunkSize: 131072 但我不知道怎么用
提前谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题