到目前为止我有这个代码,但不能得到Buffer
bianary。如何用http模块上传node.js中的文件?
var http = require('http');
var myServer = http.createServer(function(request, response)
{
var data = '';
request.on('data', function (chunk){
data += chunk;
});
request.on('end',function(){
if(request.headers['content-type'] == 'image/jpg') {
var binary = Buffer.concat(data);
//some file handling would come here if binary would be OK
response.write(binary.size)
response.writeHead(201)
response.end()
}
但得到这个错误:throw new TypeError('Usage: Buffer.concat(list, [length])');
优秀回答:) –