到目前爲止我有這個代碼,但不能得到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])');
優秀回答:) –