I am just beginning with nodejs. The following code makes a copy of the file I send via parameter in the curl.
For example curl --upload-file 11.png localhost:8080 In good theory this file, needs to have a new name that will be 111.png according to my code How do I get this name from the headers?
var http=require('http');
var fs = require('fs');
http.createServer(function(request,response){
var name = 'content-encoding';
var encoding = request.headers[name];
var newFile=fs.createWriteStream(encoding+"1");
var size=request.headers['content-length'];
var upload=0;
request.pipe(newFile);
request.on('data',function(chunck){
upload+=chunck.length;
var progress=(upload/size)*100;
response.write("progress: "+parseInt(progress,10)+ "%\n");
});
}).listen(8080);
console.log('Server Running');