-1

want to display the image which was uploaded in server,but unfortunately not getting. Image is uploaded successfully in server and changed the name in express project folder,but while fetching not getting the image. Additional route path is coming in front of image while fetching.Image is stored in server in this path "public/images/1670147053485apic.jpg"

please find my route file users.js below:

router.get('/display', (req, res) => {
  sql = `SELECT * FROM product`
  db.query(sql, (err, result) => {
    if (err) throw err
    res.render('insertDisplay', { data: result })
  })
})

also insertDisplay.hbs details below:

<table>
    <thead>
        <tr>
            <th>Product</th>
            <th>Category</th>
            <th>Time</th>
            <th>Image</th>
        </tr>
    </thead>
    <tbody>
        {{#each data}}
        <tr>
            <td>{{this.Product}}</td>
            <td>{{this.Category}}</td>
            <td>{{this.date}}</td>
            <td><img src="{{this.Image}}"></td>
        </tr>
        {{/each}}
    </tbody>
</table>

In running log am getting GET /users/1670147053485apic.jpg 404 103.009 ms - 1407

but not displaying any image

screenshot currently getting the output:

Arun K
  • 1
  • 3
  • The path is wrong – Konrad Dec 04 '22 at 11:03
  • Yes, i found it from logs. but what will be the exact reason for this problem? any idea? – Arun K Dec 04 '22 at 11:07
  • You either don't serve public folder at all or public folder is served from a different endpoint – Konrad Dec 04 '22 at 11:08
  • not getting you,guess i need to change the storage path other than public folder,please correct me if i was wrong – Arun K Dec 04 '22 at 11:13
  • Do you serve the public folder? – Konrad Dec 04 '22 at 11:15
  • image is stored in 'public/images/' path, so do i need to change this storage path? – Arun K Dec 04 '22 at 11:43
  • https://stackoverflow.com/questions/10434001/how-to-server-specifc-static-files-with-express-js – Konrad Dec 04 '22 at 12:33
  • 1
    Welcome to Stack Overflow! At the moment, your question is really hard to answer. The code you've included isn't very relevant to the problem, but what would be relevant is to see the code that stores the image, as well as the route that serves the image. If you include those, it'll be easier to answer. – Tiddo Dec 04 '22 at 21:07

1 Answers1

0

Issue Resolved:- (Express-Generator,Handlebars,MySql these are my working environment)

  1. An image file is uploaded into express application(or server) and its name is stored in database.(No Issue-uploaded successfully)
  2. But not able to display the image using handlebars,while try to display from db(this was the real issue faced).
  3. Changes made in 'insertDisplay.hbs' file, now its working( changes made)

My express app structure, images stored in 'public/images' location.

  • Screenshot for further reference:-user.js(route for insert and display image-user.js),databse.js(db connection configuration-databse.js).

Thanks for support -Konrad,Tiddo

Arun K
  • 1
  • 3