我正在用 node.js 构建一个超级简单的文件服务器。
我正在使用 dotcloud 来托管我的服务器,可以在此处访问。
当我尝试上传文件(使用正确的密码)时,我的代码返回'Error, incorrect password!'
. 看看下面的代码,我会解释原因:
var success = false;
var form = new formidable.IncomingForm();
form.parse(req, function(err,fields, files) {
console.log("Password: " + fields.password);
if(fields.password!="poop") {
return;
}
fs.rename(files.upload.path, files.upload.name, function (err) { });
success = true;
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end();
});
req.on('end', function() {
// empty 200 OK response for now
if(success) {
res.writeHead(302, { 'location': '/' });
} else {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('Error, incorrect password!\n');
}
res.end();
});
我认为我的代码在“fs.rename(files.....)”处失败,因为成功变量未设置为 true。我的代码适用于我的本地 node.js 安装,我是否需要从 dotcloud 请求写入权限或其他什么?