【问题标题】:How to convert blob file to images in Nodejs如何在 Nodejs 中将 blob 文件转换为图像
【发布时间】:2020-11-16 04:26:33
【问题描述】:

我将文件作为文件流数据类型存储在 SQL Server 数据库中,它返回一个 blob。我正在使用带有express的nodejs。有没有办法将这些 blob 转换为图像并使用 nodejs 和 express 将其发送到我的 ejs 模板?

【问题讨论】:

标签: node.js express


【解决方案1】:

const blobToImage = (blob) => {
  return new Promise(resolve => {
    const url = URL.createObjectURL(blob)
    let img = new Image()
    img.onload = () => {
      URL.revokeObjectURL(url)
      resolve(img)
    }
    img.src = url
  })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多