I am trying to post files using HTTP request on Node.js ,but after some files posted then it randomly shows [Error: socket hang up] code: 'ECONNRESET'
My code for file sending is,
var http = require('http');
var request = require('request');
var fs= require('fs');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
var serverUrl='http://localhost:3000';
function uploadFile(){
var req = request.post(serverUrl+'/api/file/upload', function (err, resp, body) {
if (err) {
console.log(err);
} else {
console.log(body);
}
});
var form = req.form();
form.append('file', fs.createReadStream('abcd.mp3'));
}
uploadFile();
server.listen(8000);
via Sabreena
No comments:
Post a Comment