简体   繁体   English

无法在express节点项目中显示上传的图片? 请支持

[英]Unable to display the uploaded image in express node project? Please support

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.图像已成功上传到服务器并更改了 express 项目文件夹中的名称,但在获取图像时未获取图像。 Additional route path is coming in front of image while fetching.Image is stored in server in this path "public/images/1670147053485apic.jpg"附加路由路径在获取时出现在图像前面。图像存储在此路径“public/images/1670147053485apic.jpg”中的服务器中

please find my route file users.js below:请在下面找到我的路由文件 users.js:

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:下面还有 insertDisplay.hbs 的详细信息:

<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在运行日志中得到 GET /users/1670147053485apic.jpg 404 103.009 ms - 1407

but not displaying any image但不显示任何图像

screenshot currently getting the output:当前获取 output 的屏幕截图:

Issue Resolved:- (Express-Generator,Handlebars,MySql these are my working environment)已解决的问题:-(Express-Generator、Handlebars、MySql 这些是我的工作环境)

  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 ) “insertDisplay.hbs”文件中所做的更改,现在可以正常工作(已进行更改

My express app structure, images stored in 'public/images' location.我的 express 应用程序结构,图像存储在“public/images”位置。

  • Screenshot for further reference:-user.js(route for insert and display image- user.js ),databse.js(db connection configuration- databse.js ).截图进一步参考:-user.js(插入和显示图片的路由-user.js ),databse.js(数据库连接配置-databse.js )。

Thanks for support -Konrad,Tiddo感谢支持-Konrad,Tiddo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM