nodeJs读取图片加载到前端Content_type如何设置

在使用nodeJs过读取图片加载到前端页面时,总是无法正确显示图片,而是下载图片
主要是content-type设置的不正确:

  1. 正确写法
res.writeHead(200, {
   "content-type": "image/jpeg"
})
  1. 错误写法
res.writeHead(200, {
   "content-type": "images/jpeg"
})
res.writeHead(200, {
   "content-type": "image/*"
})

第一种写法会正确展示图片,第二种写法会下载图片

你可能感兴趣的:(node.js,HTML5,js)