Java 以角度4渲染缩略图

Java 以角度4渲染缩略图,java,node.js,image,angular,openkm,Java,Node.js,Image,Angular,Openkm,我试图将从Java服务获取的图像渲染为InputStream,通过NodeJS Express服务器重新发送,最后以Angular4格式渲染 我是这样做的: ...compose request options... const vedica_res = await rp(options); let buffered = new Buffer(vedica_res, 'binary'); res.writeHead(200, { 'Content-Type': 'image/p

我试图将从Java服务获取的图像渲染为
InputStream
,通过NodeJS Express服务器重新发送,最后以Angular4格式渲染

我是这样做的:

...compose request options...    
const vedica_res = await rp(options);

let buffered = new Buffer(vedica_res, 'binary');
res.writeHead(200, {
    'Content-Type': 'image/png',
    'Content-disposition': 'attachment;filename=' + 'thumb.png',
    'Content-Length': buffered.length
});

return res.end(buffered, 'binary');
Java Jersey服务:

@GET
@Path("thumbnail")
@ApiOperation(
        value = "Gets document preview",
        notes = "Gets document preview"
)
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Preview of the document")
})
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("image/png")
public Response getDocThumbnail(
        @ApiParam(value = "Entity UUID", required = true) @FormDataParam("uuid") String uuid
) throws RepositoryException, UnknowException, WebserviceException, PathNotFoundException, DatabaseException, AutomationException, AccessDeniedException, ConversionException, IOException {
    RawDocument rawDocument = docCtrl.getDocThumbnail(uuid);
    return Response
            .ok(rawDocument.getInputStream(), "image/png")
            .header("Content-Disposition", "attachment; filename=\" " + rawDocument.getName() + "\"")
            .build();
}
控制器看起来像:

public RawDocument getDocThumbnail(String uuid) throws IOException, AccessDeniedException, PathNotFoundException, WebserviceException, RepositoryException, DatabaseException, ConversionException, AutomationException, UnknowException {
    return new RawDocument(
            okmWebSrv.getOkmService().getThumbnail(uuid, ThumbnailType.THUMBNAIL_LIGHTBOX),
            "whatever"
    );
}
基本上,这是一个呼吁

这个Java端点是从NodeJS Express 4.15调用的,NodeJS Express 4.15正在为这个Java后端预处理一些请求。 我是这样做的:

...compose request options...    
const vedica_res = await rp(options);

let buffered = new Buffer(vedica_res, 'binary');
res.writeHead(200, {
    'Content-Type': 'image/png',
    'Content-disposition': 'attachment;filename=' + 'thumb.png',
    'Content-Length': buffered.length
});

return res.end(buffered, 'binary');
最后,Angular4是这次往返的发起者,我尝试这样渲染图像:

this.rest.send('http://localhost:4200/vedica/api/document/thumbnail', RequestMethod.Get,
        {uuid: '19516ea1-657e-4b21-8564-0cb87f29b064'}, true).subscribe(img => {
        // this.preview = img
        var urlCreator = window.URL;
        var url = urlCreator.createObjectURL(img);
        this.thumb.nativeElement.src = url;
    })
接收到的“img”是一个
Blob{size:81515,键入:“image/png”}
。控制台不显示任何错误,但在
中不为其呈现任何图像。图像只有一个损坏的图像图标。
当我尝试读取新选项卡中的缓存响应时,它是可访问的,但不会再次呈现任何内容


你能指出我做错了什么吗?已经尝试了很多,但没有成功。

我认为问题不在于流提前关闭,我认为问题将阻碍下载,请查看此处:

从服务器端(OpenKM和用户界面之间的中间)来看,问题通常是:

//response.setContentLength(is.available()); // Cause a bug, because at this point InputStream still has not its real size.
你应该使用

response.setContentLength(new Long(doc.getActualVersion().getSize()).intValue());

通过将
request promise
替换为裸
request
包来解决此问题,该包用于向java BE发出此请求,并通过管道将回复直接传递到角FE的包装响应中:

let reply = request(options);
reply.pipe(res);

我真的不知道如何将其融入我的上下文中,对不起,我不知道如何使用Angular,但是使用标准servlet,正如我所解释的,我们遇到的问题已经解决了。似乎流停止读取,我不知道变量buffered.length是否对其有影响。我建议在冲洗输出流之前,在中间尝试一个步骤,例如将图像保存到文件系统中并检查它是否正确。稍后尝试一步冲洗。