在Express.js中,我想将我的图像/视频保存在Express.js项目文件夹之外,这意味着不在公共/图像中.例如,现在我的媒体位于Express.js项目文件夹中: /home/myName/Project/public/images 而且我希望我的图
/home/myName/Project/public/images
而且我希望我的图片/视频能够存在
/home/myName/allMyMedia
我的app.configure()函数现在看起来像这样:
app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(expressValidator); app.use(express.methodOverride()); app.use(express.cookieParser('your secret here')); app.use(express.session()); app.use(app.router); app.use(require('less-middleware')({ src: __dirname + '/public' })); app.use(express.static(path.join(__dirname, 'public'))); });
我试图将’/ public’改为’../public’,但这不起作用.我也玩了一些关于公开的其他路径声明,但最多知道我无法弄清楚如何解决这个问题.任何帮助,将不胜感激.
如果要从媒体文件夹和公共文件夹中的其他人请求某些请求,请调用静态两次,如 https://github.com/visionmedia/express/blob/master/examples/static-files/index.js所示(具有良好的注释)var express = require('../..'); var app = express(); app.use(express.logger('dev')); app.use(express.static(__dirname + '/public')); app.use(express.static('/home/myName/allMyMedia/')); app.use(app.router); app.listen(3000); // GET /images/foo.jpg will first check ./public/images/foo.jpg, // then /home/myName/allMyMedia/images/foo.jpg, // then it will attempt to match a routing function to '/images/foo.jpg' // As usual, as soon as something sends a response, no further functions are called. // Reorder the app.use stack to change this order.