简体   繁体   English

客户端与服务器映像过程并显示

[英]Client vs server image process and shown

Client vs server imagen process. 客户端与服务器映像过程。

We got a big system which runs on JSF(primefaces) EJB3 and sometimes JavaScript logic (like for using firebase and stuff). 我们得到了一个大型系统,该系统可以在JSF(primefaces)EJB3上运行,有时还可以在JavaScript逻辑上运行(例如使用Firebase和东西)。

So we run onto this problem, we have a servlet to serve some images. 因此,我们遇到了这个问题,我们有一个servlet来提供一些图像。 Backend take a query, then extract some blob img from DB, make that BLOB into array of bytes, send it to browser session memory and servlet take it to serve it in ulr-OurSite/image/idImage . 后端进行查询,然后从数据库中提取一些blob img,将BLOB制成字节数组,将其发送到浏览器会话内存,然后servlet将其接收到ulr-OurSite / image / idImage中进行服务 Front end calls it by <img>(url/image/id)</img> and works fine so far. 前端通过<img>(url/image/id)</img>调用,到目前为止效果还不错。

Then we are using a new direct way to show img, we send BLOB/RAW data to frontend and there we just convert them into Base64.imageReturn. 然后,我们使用一种新的直接方式来显示img,将BLOB / RAW数据发送到前端, 然后将它们转换为Base64.imageReturn。 and pass it to html. 并将其传递给html。

 Base64 codec = new Base64();
                String encoded = codec.encodeBase64String(listEvidenciaDev.get(i).getImgReturns());

Both work, for almost all cases. 对于几乎所有情况,这两种方法都有效。

Note: We didn't try this before because we couldn't pass the RAW data through our layers of serialized objects and RMI. 注意:我们之前没有尝试过此操作,因为我们无法将RAW数据通过序列化对象和RMI的层传递。 Now we can of course. 现在我们可以了。

So now there are two ways. 所以现在有两种方法。

Either we send data to servlet and put it on some url, which means the backend does all the job and frontend just calls url 我们要么将数据发送到servlet并将其放在某个url上,这意味着后端完成所有工作,而前端仅调用url

or we send data to frontend which is going to make some magic and transform it to img. 或者我们将数据发送到前端,这将使魔术变得神奇,并将其转换为img。

This brings 2 questions. 这带来了两个问题。

  1. If we send to frontend RawObject or make them call URL to show his image content, final user download the same amount of data? 如果我们发送到前端RawObject或让他们调用URL以显示其图像内容,最终用户将下载相同数量的数据吗? This is important because we have some remote branch offices with poor internet connection 这很重要,因为我们有些远程分支机构的互联网连接较差

  2. Is worth pass the hard work to frontend (convert data) or backend (convert and publish)? 值得将艰苦的工作传递给前端(转换数据)或后端(转换和发布)吗?


EDIT: 编辑:

My questions is not about BLOB ( the one i call RAW data ) being bigger than base64 我的问题不是BLOB( 我称为RAW数据 )大于base64的问题。

It is; 它是; passing the data as object and transform it to a readable picture is more heavy to internet bandwidth than passing a url from our servlet with the actual IMG and load it on html ? 将数据作为对象传递并将其转换为可读图片比使用实际IMG从我们的servlet中传递url并将其加载到html上要重得多。

I did choose to close this answer because we did some test and it was the same bandwidth usage on front end. 我确实选择了关闭该答案,因为我们进行了一些测试,并且前端使用了相同的带宽。

Anyway we make use of both solutions 无论如何,我们同时使用两种解决方案

If we dont want to charge frontend making a lot of encode we set a servlet for that images (that comes with more code and more server load). 如果我们不希望前端进行大量编码,我们会为该图像设置一个servlet(带有更多代码和更多服务器负载)。 We look for the best optimization on specific cases. 我们寻求针对特定情况的最佳优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM