简体   繁体   English

在node.js和express中,客户端应如何向服务器发送多达3k的大量数据?

[英]In node.js and express, how should a client send a large, up to 3k, amount of data to the server?

the client will be sending my server a change log, containing a list of commands and parameters, JSON or not is TBD. 客户端将向我的服务器发送更改日志,其中包含命令和参数列表,JSON是否为TBD。

This payload can be a 3 or 4K not likely to be more. 该有效载荷可以是3K或4K,不太可能更多。

What is the standard approach to deal with requirement? 处理需求的标准方法是什么? Client should send a json, containing all of the changes, as part of the request body? 客户端应该发送包含所有更改的json作为请求正文的一部分吗?

Any recommendations? 有什么建议吗? Lessons learned? 得到教训?

Just POST the data. 只需发布数据即可。 3-4 KB is nothing unless you're dealing with feature-phone WAP browsers in the middle of rural India, performance issues of the "OMG, I'm Google and care about every byte ever because of my zillion-user userbase" type, or something like that. 除非您在印度中部的中部地区使用功能电话WAP浏览器,否则3-4 KB就什么也不是了,“ OMG,我是Google,并且因为我的亿万用户用户群而关心每个字节”类型的性能问题, 或类似的东西。

If you're really worried about payload size, you can gzip-base64 encode it before sending - but only do this if a) you really care about this (which is unlikely) and b) your payload is large enough that this saves you bandwidth. 如果您真的很担心有效负载的大小,可以在发送之前gzip-base64对其进行编码-但只有在以下情况下才执行此操作:a)您真的很在乎(不太可能),并且b)有效负载足够大以节省带宽。 (gzip-base64'ing small payloads often increases their size, since there isn't enough data to get enough compression benefit to offset the 33% size increase from base64 encoding.) (gzip-base64的小型有效负载通常会增加其大小,因为没有足够的数据来获得足够的压缩优势,无法抵消base64编码增加的33%的大小。)

You can set the maximun upload size with 您可以通过以下方式设置最大上传大小

app.use(express.limit('5mb'));

if that's an issue? 如果有问题吗?

But, there shouldn't really be any limitations on this as default, except the max buffer size (which I believe is 1GB). 但是,默认情况下,除了最大缓冲区大小(我认为是1GB)外,实际上应该没有任何限制。

It also sounds like this is something that you can just post to the server with a regular POST request, in other words you use a form with a file input and just upload the file the regular way, as 4kb isn't really a big file. 这听起来也像您可以通过常规POST请求将其发布到服务器上一样,换句话说,您可以使用带有文件输入的表单并以常规方式上载文件,因为4kb并不是很大的文件。

You can use a normal JSON post to send across 3/4K of data. 您可以使用普通的JSON帖子来发送3 / 4K数据。

You should pay more attention to what you do with the data received on the server side, whether you buffer up all data before you start processing them (store in db or elsewhere), or process them in chunks. 无论在开始处理它们(存储在db还是其他地方)之前缓冲所有数据,还是分块处理它们,您都应该更加注意如何处理服务器端接收到的数据。 If you are simply dumping the data into files on server, you should create a Writable stream and pump chunks of data received into the stream. 如果只是将数据转储到服务器上的文件中,则应创建可写流并将接收到的数据块泵入流中。

How are you going to process the received data on the server? 您将如何处理服务器上收到的数据? But then, 3/4K is not really worrying amount of data. 但是,3 / 4K并不是真正令人担心的数据量。

暂无
暂无

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

相关问题 Node.js Express 向客户端 vanilla JS 发送大量数据 - Node.js Express send huge data to client vanilla JS 如何使用node.js服务器处理大量负载? - How to handle large amount of load with node.js server? 如何使用 Node.js express 从服务器向客户端发送实时 stream 响应 - How to send real time stream response from server to client using Node.js express 如何使用 Node.js express 从服务器向客户端发送实时响应 - How to send real time response from server to client using Node.js express 如何使用 Pusher 将用户的存款和取款详细信息从客户端发送到 Node.js(快递)服务器? - How to send deposit and withdraw details of user from client to Node.js (express) server using Pusher? 如何使用Node.js异步查询大量数据? - How to asynchronously query a large amount of data with Node.js? 如何在A node.js / express服务器上接收一些文件并将文件发送到B node.js / express服务器 - How to receive some files at A node.js/express server and send files to B node.js/express server 如何将数据服务器(用JAVA编写)发送到客户端(用Node.js编写) - How to send data server (written in JAVA) to client (Written in Node.js) 如何将数据作为响应从Node.js服务器发送到AJAX客户端? - How do I send data as a response from Node.js server to AJAX client? 如何将数据从Node.js(webpack)发送到纯Node.js(express)? - How to send data from Node.js(webpack) to pure Node.js(express)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM