URL:: 54.218.71.244:7002/Details/?key=images
var express=require('express');
var mysql=require('mysql');
var fs=require('fs');
var http=require('http');
var app=express();
var connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'root',
database:'posting_only_image_DB'
});
connection.connect();
app.set('port',process.env.PORT||7002);
app.use(express.static(__dirname+'/public/images'));
app.use(express.bodyParser());
app.post('/Details/',function(req,res){
var path=req.files.key.name;
connection.query('INSERT INTO MyTable(image)',[path],function(err,rows,fields)
{
console.log('Connection result error', +err);
});
});
http.createServer(app).listen(app.get('port'),function(){
console.log('Express server listening on port'+app.get('port'));
});
我遇到错误 ::
Express server listening on port7002
Connection result error NaN
Error: Request aborted
at IncomingMessage.<anonymous> (/home/ubuntu/rainmelon/sample_programs/image_express/node_modules/express/node_modules/connect/node_modules/multiparty/index.js:93:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1886:11)
at Socket.serverSocketCloseListener (http.js:1898:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:451:12)
答案 0 :(得分:2)
您正在尝试将err
转换为数字:
console.log('Connection result error', +err);
^
要么使用它:
if (err) {
console.log('Connection result error: ' + err);
}
或者这(推荐);
if (err) {
console.log('Connection result error:', err);
}
我也没有看到你结束请求(使用res.send()
或res.render
或其他),你应该这样做。