picture do not show in sails.js view

30 views
Skip to first unread message

mloc...@gmail.com

unread,
Feb 8, 2018, 2:09:11 AM2/8/18
to sails.js


My assets folder : 

1assets 
2     | images 
3            | media 
4                  | book 
5                        | pictures

i want to create new book when i upload book picture in above path, But when i try to show this image in view, the image can not be displayed and there is no error either. 
my code is: 

//BookController
02create: function (request, response, next) {
03var title = request.body.title;
04var subject = request.body.subject;
05var brief = request.body.brief;
06var author = request.body.author;
07var origin_pic_name = null;
08 
09request.file('pic').upload({
10  dirname: '../../assets/images/media/book/pictures/',
11},function (err, file) {
12  if(err) console.log(err);
13  origin_pic_name = file[0]['fd'].split('\\').reverse()[0] ;
14 
15  Book.create({title:title,subject:subject,brief:brief,author:author,pic:origin_pic_name}).exec(function (err) {
16    if(err) response.end(500, {error: 'Database Error'});
17    response.redirect('/');
18  });
19 
20});}, 
21 
22index : function (request, response, next) {
23Book.find({}).exec(function (err, books) {
24  if(err) response.end(500, {error: 'Database Error'});
25  response.view('book/index', {books:books});
26});}, 
27 
28//my index.ejs
29<ol>
30<% books.forEach(function (value) {%>
31  <h3><li> <%= value.title %></li></h3>
32  <ul><%= value.author %></ul>
33  <ul><%= value.subject %></ul>
34  <ul><%= value.brief %></ul>
35  <ul><img src="/images/media/book/pictures/<%= value.pic %>"/></ul>
36<% })%>
37</ol>

thank you
Reply all
Reply to author
Forward
0 new messages