function upload2(id){

console.log("开始上传");
var localpath = "文件路径";
var remotepath = "文件路径";

var localname = "local" +id+".webm";

var remotename = "remote" +id+".webm";

var boundaryKey = '----WebKitFormBoundary' + new Date().getTime();

var options = {
host:"127.0.0.1",//远端服务器域名
port:80,//远端服务器端口号
method:'POST',
path:'/upload',//上传服务路径
headers:{
'Content-Type':'multipart/form-data; boundary=' + boundaryKey,
}
};

var req = http.request(options,function(res){
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(boundaryKey);
console.log('body: ' + chunk);
});
res.on('end',function(){
hebing(id);
console.log('res end.');
});
});

req.write(
'--' + boundaryKey + '\r\n' +
'Content-Disposition: form-data; name="file"; filename='+remotename+'\r\n' +
'Content-Type:video/webm\r\n\r\n'
);

var fileStream = fs.createReadStream(remotepath,{bufferSize:1024 * 1024 * 50});
fileStream.pipe(req,{end:false});
fileStream.on('end',function(){
req.end('\r\n--' + boundaryKey + '--');
});
}

posted on 2017-08-15 16:58  大峰1992  阅读(418)  评论(0编辑  收藏  举报