我希望"client.js“读取一个文件,并使用HTTP POST通过"server.js”将其上传到某个文件夹。当文件大小较小(1KB)时,它可以正常工作。但当文件较大(可能在100KB左右)时,它就不起作用了。没有错误,但存储的图像的大小比它应该的大小小。我也不知道原因。请帮帮忙。
1.client.js
var fs = require('fs');
var http = require('http');
postData = null;
postData=fs.readFileSync("test.jpg")
if(postData!=null){
var options = {
host: 'localhost',
port: 10730,
method: 'POST'
};
var clientRequest = http.request(options);
clientRequest.end(postData);}2.server.js
var http = require('http');
var fs = require('fs');
var server = http.createServer((req,res)=>{
req.on('data', (chunk)=>{
fs.writeFile('testcopy.jpg',chunk)})
req.on('end', ()=>{
console.log("end")
})})
server.listen(10730,'localhost');提前谢谢你。
https://stackoverflow.com/questions/38458921
复制相似问题