【问题标题】:How to re-translate image from other website (hiding source URL)如何从其他网站重新翻译图像(隐藏源 URL)
【发布时间】:2019-10-26 13:19:43
【问题描述】:

我有一个图片链接,比如 thisthat

我正在尝试将此图像从其他源 URL 重新翻译为某个链接,例如 http(s)://examplewebsite.com/john。 因此,它不需要是重定向,而是在不同的链接上“显示”图像。我试过使用express.static,但它不起作用。

提前致谢

【问题讨论】:

    标签: node.js image express url


    【解决方案1】:

    如果我理解正确,你有你的快递服务器,你想在隐藏源网址的同时包含外国图像作为响应

    在最简单的形式中,每次有人请求您的页面时,您都会获取所需的图像,将其编码为 base64 并将这个 base64 包含为 src 用于 img

    const express = require('express')
    const fetch = require('node-fetch')
    const app = express()
    const port = 3000
    
    app.get('/', (req, res) => {
      fetch('https://www.gravatar.com/avatar/fdb4d2674d818861be4a4139469ebe59?s=48&d=identicon&r=PG&f=1')
        .then(res => res.buffer())
        .then(buffer => {
          res.send(`
          <!doctype html>
          <html lang="en">
          <head>
          <meta charset="UTF-8">
             <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
                 <meta http-equiv="X-UA-Compatible" content="ie=edge">
             <title>Document</title>
          </head>
          <body>
            <p>hello</p>
            <img src="data:image\png;base64, ${buffer.toString('base64')}" alt="image">
          </body>
          </html>
      `)
        })
    
    })
    
    app.listen(port, () => console.log(`Example app listening on port ${port}!`))
    

    理想情况下,您应该为这些图像创建一个单独的端点,并将它们缓存(在内存中或硬盘上),以免每次需要它们时都重新下载它们

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多