I want "client.js" to read a file, and upload it to a certain folder via "server.js" using HTTP POST. When file size is small(1kb), it works. But when file size is bigger(maybe around 100kb), it doesen't work. There is no error, but the stored image is less in size than what it's supposed to be. I don't know why. please help.
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');
Thank you in advance.