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










share|improve this question





















  • 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














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










share|improve this question





















  • 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












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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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
















  • 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















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto