while trying uploaing nothing is happening
i want to upload a file by node.js so i try by this article. http://debuggable.com/posts/parsing-file-uploads-at-500-mb-s-with-node-js:4c03862e-351c-4faa-bb67-4365cbdd56cb
I run this code
var formidable = require('formidable')
, http = require('http')
, sys = require('sys');
var serv开发者_高级运维er=http.createServer(function(req, res) {
console.log('out if condition'+sys.inspect(req));
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
// parse a file upload
console.log('in if condition');
var form = new formidable.IncomingForm();
form.parse(req, function(fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(sys.inspect({fields: fields, files: files}));
});
return;
}
// show a file upload form
res.writeHead(200, {'content-type': 'text/html'});
res.end
( '<form action="/upload" enctype="multipart/form-data" method="post">'
+ '<input type="text" name="title"><br>'
+ '<input type="file" name="upload" multiple="multiple"><br>'
+ '<input type="submit" value="Upload">'
+ '</form>'
);
});
server.listen(8000);
when i upload the file it doesn't proceed further easily and doesn't go in if condition of upload why ?
fs.writeFile(files.upload.name, files.upload,'utf8', function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
Please check.
http://rahulmehta1.wordpress.com/2011/04/26/uploading-a-file-in-node-js-by-formidable/
精彩评论