Send/receive 图像与 http 反应
Send/receive images in react with http
我们目前正在开发一个带有 React 前端(和 express 服务器)和 Java 后端的应用程序。该应用程序必须能够在前端和后端之间发送大量图像和视频。
到目前为止,我们已经使用 fetch (https://github.com/github/fetch) 将带有 formData 的图像从前端发送到后端,但是由于 fetch 中未实现的 formData,这不适用于以其他方式(后端到前端)发送。我们能够以 blob 形式接收图像,但希望通过文件发送信息以减少 http 请求的数量。
对于我们应该使用什么来发送和接收大量图像和视频,有没有人有任何建议?图书馆或建议?
非常感谢!
我真的没有发现通过多个请求接收数据有任何问题。一个请求发送图像的信息,带有 link 到图像,然后浏览器发送另一个请求来获取图像。这是我见过的最常见的实现方式。
向服务器发送多个请求的感知开销并不是真正的问题。现代浏览器不会打开到服务器的多个 tcp 连接——它们会保持连接打开一段时间以允许多个请求,而无需打开新连接的开销。
All modern web browsers use persistent connections, including Google Chrome, Firefox, Internet Explorer (since 4.01), Opera (since 4.0) and Safari.
https://en.wikipedia.org/wiki/HTTP_persistent_connection
我假设您尝试使用 "formData" 向浏览器发送响应的目的是在响应中使用 content-type: multipart
。这不是一个常见的做法,浏览器支持 looks inconsistent. Also, 。
不过,采用 HTTP/2 对您的用例真正有利。 HTTP/2 具有更多持久连接和同一连接的多个响应的功能。
With the new binary framing mechanism in place, HTTP/2 no longer needs multiple TCP connections to multiplex streams in parallel; each stream is split into many frames, which can be interleaved and prioritized. As a result, all HTTP/2 connections are persistent, and only one connection per origin is required, which offers numerous performance benefits.
https://developers.google.com/web/fundamentals/performance/http2/
我们目前正在开发一个带有 React 前端(和 express 服务器)和 Java 后端的应用程序。该应用程序必须能够在前端和后端之间发送大量图像和视频。
到目前为止,我们已经使用 fetch (https://github.com/github/fetch) 将带有 formData 的图像从前端发送到后端,但是由于 fetch 中未实现的 formData,这不适用于以其他方式(后端到前端)发送。我们能够以 blob 形式接收图像,但希望通过文件发送信息以减少 http 请求的数量。
对于我们应该使用什么来发送和接收大量图像和视频,有没有人有任何建议?图书馆或建议?
非常感谢!
我真的没有发现通过多个请求接收数据有任何问题。一个请求发送图像的信息,带有 link 到图像,然后浏览器发送另一个请求来获取图像。这是我见过的最常见的实现方式。
向服务器发送多个请求的感知开销并不是真正的问题。现代浏览器不会打开到服务器的多个 tcp 连接——它们会保持连接打开一段时间以允许多个请求,而无需打开新连接的开销。
All modern web browsers use persistent connections, including Google Chrome, Firefox, Internet Explorer (since 4.01), Opera (since 4.0) and Safari. https://en.wikipedia.org/wiki/HTTP_persistent_connection
我假设您尝试使用 "formData" 向浏览器发送响应的目的是在响应中使用 content-type: multipart
。这不是一个常见的做法,浏览器支持 looks inconsistent. Also, 。
不过,采用 HTTP/2 对您的用例真正有利。 HTTP/2 具有更多持久连接和同一连接的多个响应的功能。
With the new binary framing mechanism in place, HTTP/2 no longer needs multiple TCP connections to multiplex streams in parallel; each stream is split into many frames, which can be interleaved and prioritized. As a result, all HTTP/2 connections are persistent, and only one connection per origin is required, which offers numerous performance benefits. https://developers.google.com/web/fundamentals/performance/http2/