Express image upload and view in jade

佐手、 提交于 2019-12-06 04:29:50

You need to know that Express configure your public directory a little bit differently than other traditional servers like Apache. I guess that for displaying static assets, your line looks like this:

app.use(express.static(__dirname + '/public'));

That'll be the only publicly viewable folder in your app. This is why Express find it redundant to add the name of the directory to the url. The url doesn't reflect your actual folder structure.

But req.files does show the actual path so that you can manipulate it in your app, or else it'd be unusable elsewhere. My solution would be to directly refer to src = '/images/imageName.jpg' in Jade. You'd have to pass the actual image name as parameter. Or, you can just strip the "public" part from req and pass it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!