Display images on page in node+express+mysql+cloud9
up vote
0
down vote
favorite
I have stored an image in directory and saved the path in a mysql table. I am trying to display the image on my ejs page. But it is not displayed. Everything is setup on cloud9. Please tell me what am I doing wrong.
Express file:
var express=require("express");
var app=express();
var mysql=require("mysql");
app.use(express("/home/ubuntu/workspace/Practice"));
var con=mysql.createConnection(
host:"127.0.0.1",
user:"akarmalkar",
password:"",
database:"c9"
);
con.connect(function(err)
if(err) throw err;
console.log("Connection Established");
/*var sql="select poster from tbl_movies";*/
var sql="select poster from tbl_movies";
con.query(sql,function(err,result)
if(err) throw err;
console.log(result[0].poster);
app.get("/:thing",function(req,res)
res.render("tempEjs.ejs",resultVar: result[0].poster);
);
);
);
app.listen(process.env.PORT,process.env.IP,function()
console.log("Server Started");
);
EJS file:
<img src="<%=resultVar%>" width="200px" height="100">
Screenshot of mysql table and folder structure
mysql node.js express cloud9
add a comment |
up vote
0
down vote
favorite
I have stored an image in directory and saved the path in a mysql table. I am trying to display the image on my ejs page. But it is not displayed. Everything is setup on cloud9. Please tell me what am I doing wrong.
Express file:
var express=require("express");
var app=express();
var mysql=require("mysql");
app.use(express("/home/ubuntu/workspace/Practice"));
var con=mysql.createConnection(
host:"127.0.0.1",
user:"akarmalkar",
password:"",
database:"c9"
);
con.connect(function(err)
if(err) throw err;
console.log("Connection Established");
/*var sql="select poster from tbl_movies";*/
var sql="select poster from tbl_movies";
con.query(sql,function(err,result)
if(err) throw err;
console.log(result[0].poster);
app.get("/:thing",function(req,res)
res.render("tempEjs.ejs",resultVar: result[0].poster);
);
);
);
app.listen(process.env.PORT,process.env.IP,function()
console.log("Server Started");
);
EJS file:
<img src="<%=resultVar%>" width="200px" height="100">
Screenshot of mysql table and folder structure
mysql node.js express cloud9
what does this line log to console?console.log(result[0].poster);
– Majid Sajadi
Nov 10 at 16:15
It prints the value of 'poster' column of the first row, i.e. logan.jpg in this case.
– Apoorv
Nov 10 at 16:19
where do you save your images? this is probably a route related problem. i need to know where exactly you saved you images and what is saved in your database.
– Majid Sajadi
Nov 10 at 16:22
If you are trying to avoid an extra HTTP call, then you can probablybase64
encode the image and then use that in your template. Check this answer on how to do that.
– Pramodh Valavala
Nov 11 at 2:55
I've done it. The path for static folder of images was incorrect. Now I've changed it and everything seems to work fine.
– Apoorv
Nov 11 at 7:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have stored an image in directory and saved the path in a mysql table. I am trying to display the image on my ejs page. But it is not displayed. Everything is setup on cloud9. Please tell me what am I doing wrong.
Express file:
var express=require("express");
var app=express();
var mysql=require("mysql");
app.use(express("/home/ubuntu/workspace/Practice"));
var con=mysql.createConnection(
host:"127.0.0.1",
user:"akarmalkar",
password:"",
database:"c9"
);
con.connect(function(err)
if(err) throw err;
console.log("Connection Established");
/*var sql="select poster from tbl_movies";*/
var sql="select poster from tbl_movies";
con.query(sql,function(err,result)
if(err) throw err;
console.log(result[0].poster);
app.get("/:thing",function(req,res)
res.render("tempEjs.ejs",resultVar: result[0].poster);
);
);
);
app.listen(process.env.PORT,process.env.IP,function()
console.log("Server Started");
);
EJS file:
<img src="<%=resultVar%>" width="200px" height="100">
Screenshot of mysql table and folder structure
mysql node.js express cloud9
I have stored an image in directory and saved the path in a mysql table. I am trying to display the image on my ejs page. But it is not displayed. Everything is setup on cloud9. Please tell me what am I doing wrong.
Express file:
var express=require("express");
var app=express();
var mysql=require("mysql");
app.use(express("/home/ubuntu/workspace/Practice"));
var con=mysql.createConnection(
host:"127.0.0.1",
user:"akarmalkar",
password:"",
database:"c9"
);
con.connect(function(err)
if(err) throw err;
console.log("Connection Established");
/*var sql="select poster from tbl_movies";*/
var sql="select poster from tbl_movies";
con.query(sql,function(err,result)
if(err) throw err;
console.log(result[0].poster);
app.get("/:thing",function(req,res)
res.render("tempEjs.ejs",resultVar: result[0].poster);
);
);
);
app.listen(process.env.PORT,process.env.IP,function()
console.log("Server Started");
);
EJS file:
<img src="<%=resultVar%>" width="200px" height="100">
Screenshot of mysql table and folder structure
mysql node.js express cloud9
mysql node.js express cloud9
asked Nov 10 at 15:08
Apoorv
83
83
what does this line log to console?console.log(result[0].poster);
– Majid Sajadi
Nov 10 at 16:15
It prints the value of 'poster' column of the first row, i.e. logan.jpg in this case.
– Apoorv
Nov 10 at 16:19
where do you save your images? this is probably a route related problem. i need to know where exactly you saved you images and what is saved in your database.
– Majid Sajadi
Nov 10 at 16:22
If you are trying to avoid an extra HTTP call, then you can probablybase64
encode the image and then use that in your template. Check this answer on how to do that.
– Pramodh Valavala
Nov 11 at 2:55
I've done it. The path for static folder of images was incorrect. Now I've changed it and everything seems to work fine.
– Apoorv
Nov 11 at 7:29
add a comment |
what does this line log to console?console.log(result[0].poster);
– Majid Sajadi
Nov 10 at 16:15
It prints the value of 'poster' column of the first row, i.e. logan.jpg in this case.
– Apoorv
Nov 10 at 16:19
where do you save your images? this is probably a route related problem. i need to know where exactly you saved you images and what is saved in your database.
– Majid Sajadi
Nov 10 at 16:22
If you are trying to avoid an extra HTTP call, then you can probablybase64
encode the image and then use that in your template. Check this answer on how to do that.
– Pramodh Valavala
Nov 11 at 2:55
I've done it. The path for static folder of images was incorrect. Now I've changed it and everything seems to work fine.
– Apoorv
Nov 11 at 7:29
what does this line log to console?
console.log(result[0].poster);
– Majid Sajadi
Nov 10 at 16:15
what does this line log to console?
console.log(result[0].poster);
– Majid Sajadi
Nov 10 at 16:15
It prints the value of 'poster' column of the first row, i.e. logan.jpg in this case.
– Apoorv
Nov 10 at 16:19
It prints the value of 'poster' column of the first row, i.e. logan.jpg in this case.
– Apoorv
Nov 10 at 16:19
where do you save your images? this is probably a route related problem. i need to know where exactly you saved you images and what is saved in your database.
– Majid Sajadi
Nov 10 at 16:22
where do you save your images? this is probably a route related problem. i need to know where exactly you saved you images and what is saved in your database.
– Majid Sajadi
Nov 10 at 16:22
If you are trying to avoid an extra HTTP call, then you can probably
base64
encode the image and then use that in your template. Check this answer on how to do that.– Pramodh Valavala
Nov 11 at 2:55
If you are trying to avoid an extra HTTP call, then you can probably
base64
encode the image and then use that in your template. Check this answer on how to do that.– Pramodh Valavala
Nov 11 at 2:55
I've done it. The path for static folder of images was incorrect. Now I've changed it and everything seems to work fine.
– Apoorv
Nov 11 at 7:29
I've done it. The path for static folder of images was incorrect. Now I've changed it and everything seems to work fine.
– Apoorv
Nov 11 at 7:29
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240251%2fdisplay-images-on-page-in-nodeexpressmysqlcloud9%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what does this line log to console?
console.log(result[0].poster);
– Majid Sajadi
Nov 10 at 16:15
It prints the value of 'poster' column of the first row, i.e. logan.jpg in this case.
– Apoorv
Nov 10 at 16:19
where do you save your images? this is probably a route related problem. i need to know where exactly you saved you images and what is saved in your database.
– Majid Sajadi
Nov 10 at 16:22
If you are trying to avoid an extra HTTP call, then you can probably
base64
encode the image and then use that in your template. Check this answer on how to do that.– Pramodh Valavala
Nov 11 at 2:55
I've done it. The path for static folder of images was incorrect. Now I've changed it and everything seems to work fine.
– Apoorv
Nov 11 at 7:29