使用一个请求/响应下载多个PNG(nodejs) [英] Download multiple PNGs with one request/response (nodejs)

查看:353
本文介绍了使用一个请求/响应下载多个PNG(nodejs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具体问题:

我有一个请求,发送到nodejs express应用程序,该应用程序将返回多个PNG。结果直接显示在浏览器中的图像中。

I have a single request, sent to an nodejs express application, which shall return multiple PNGs. The result is displayed directly in an image in the browser.

image.src = http://www.....

PNG是在服务器端创建的,但我无法在一个响应中显示它们并显示他们在浏览器中的客户端作为图像。

The PNGs are created server side, but I do not manage to send them back in one response and display them client side in the browser as images.

我在流中传输了PNG内容,我发回了。当所有文件都被发回时,我在最后关闭了流。我之间没有调用res.end()。

I piped the PNG content in a stream, which I sent back. I closed the stream at the end, when all files were sent back. I did not call res.end() in between.

我收到的PNG文件真的很大(所以我知道它包含所有的数据)我请求的图像),但我在浏览器中的图像只显示第一个PNG - 我不知道如何拆分响应客户端以查看我的所有图像。

What happens is that I receive a PNG File, really big (so I know it contains the data of all the images I requested), but my image in the browser only displays the first PNG - and I dont know how to split the response client side to view all my images.

I如果我直接在我的电脑上下载它们(通过手动调用请求),甚至无法查看PNG - 返回的PNG非常大,但是当我打开它时只显示第一个PNG,例如在gwenview中。

I even can't view the PNGs if I download them directly on my pc (by calling the request manually) - the returning PNG is really big, but does only display the first PNG when I open it for example in gwenview.

没有选项可以在一个zip文件中发送png并将其解压缩到客户端,因为并非所有浏览器都支持解压缩。 (我很难学习这个)我真的不知道如何解决这个问题。我是否需要设置一个我还不知道的特定标题类型?我需要在PNG之间发送一些分隔符吗?如何拆分返回的PNG客户端?

It is no option to send the pngs in an zip file and extract it client side, because not all browser do support the unzipping. (I had a hard time learning this) I really dont know how to solve this problem. Do I need to set a specific header type I do not know yet? Do I need to send some delimiter inbetween the PNGs? How can I split the returning PNG client side?

非常感谢一些帮助!

谢谢!

推荐答案

多个图像没有MIME类型。您最好的选择是生成一个单独的html页面,然后将图像嵌入其中。如果您不想保留服务器上的任何图像,可以使用数据URL嵌入它们: https: //github.com/heldr/datauri

There's no MIME type for multiple images. Your best bet is to generate a single html page and then embed the images in it. If you don't want to keep any of the images on your server, you can embed them using a data URL: https://github.com/heldr/datauri

这篇关于使用一个请求/响应下载多个PNG(nodejs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆