我们目前在尝试使用移动浏览器时遇到图像上传挂起的问题,但在使用开发计算机时却没有。我们认为 express.bodyParser 中间件是罪魁祸首,因为它没有访问我们服务器中的代码。我们正在使用节点 0.10.11 并表示 3.2.5
这是相关的服务器代码
// --- Server Setup --- \\
var server = express();
// all environments
server.set('port', process.env.PORT || 3000);
server.engine('ejs', engine);
server.set('views', __dirname + '/views');
server.set('view engine', 'ejs');
server.use(express.favicon());
server.use(express.logger('dev'));
server.use(express.json())
server.use(express.urlencoded())
server.use(express.methodOverride());
server.use(express.cookieParser('your secret here'));
server.use(express.session());
//Passport stuff
server.use(passport.initialize());
server.use(passport.session());
server.use(express.static(path.join(__dirname, 'public')));
server.use(server.router);
// development only
if ('development' == server.get('env')) {
server.use(express.errorHandler());
}
// This is the problem route, mw.validateUID just validates the uid and we know that is working
// where as it seems to stop working at the express.bodyParser
server.post('/photo/:uid', mw.validateUID, express.bodyParser({'keepExtensions': true}), express.limit('2mb'), app.uploadPhoto);
相关调用代码
RestClient = function() {
var xhr = new XMLHttpRequest();
function init() {
return {
postImage: function(path, image, callback) {
if (image.size > 2500000) {
callback(-1);
return;
}
var formData = new FormData();
formData.append('photo', image);
xhr.open('POST', path, true);
xhr.send(formData);
xhr.onreadystatechange = function() {
if (this.readyState == this.DONE) {
callback(this.status);
}
};
}
}
}
和
processImage = function(imageFile) {
if (user.getId()) {
restClient.postImage('/photo/' + user.getId(), imageFile, function(status) {
if (status < 0) {
alert("Your image must be less than 2.5M in size.");
} else if (status == 200) {
reset(true);
if (!successView) {
successView = SuccessView();
}
successView.show();
} else {
alert("Sorry, we're unable to upload your photo. Please try again later.");
}
});
} else {
alert('login to fb!');
}
}
编辑:
这也是我们遇到的错误消息。
Error: Request aborted
at IncomingMessage.<anonymous> (/home/pinnacle_vodka/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js:107:19)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1881:11)
at Socket.serverSocketCloseListener (http.js:1893:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:466:12)