Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何从其他网站重新翻译图像(隐藏源URL)_Node.js_Image_Express_Url - Fatal编程技术网

Node.js 如何从其他网站重新翻译图像(隐藏源URL)

Node.js 如何从其他网站重新翻译图像(隐藏源URL),node.js,image,express,url,Node.js,Image,Express,Url,我有一个像这样的图片链接 或者 我正在尝试将此图像从其他源URL重新翻译到某个链接,例如http(s)://examplewebsite.com/john。 所以,它不需要重定向,而是在不同的链接上“显示”图像。我尝试过使用express.static,但不起作用 提前感谢如果我理解正确,您有您的express服务器,您希望在隐藏源url的同时包含外国图像作为响应 以最简单的形式,每次有人请求您的页面时,您都会获取所需的图像,将其编码为base64,并将此base64作为img的src cons

我有一个像这样的图片链接 或者

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


提前感谢

如果我理解正确,您有您的express服务器,您希望在隐藏源url的同时包含外国图像作为响应

以最简单的形式,每次有人请求您的页面时,您都会获取所需的图像,将其编码为
base64
,并将此base64作为img的
src

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}!`))
const express=require('express'))
const fetch=require('node-fetch')
const app=express()
常数端口=3000
应用程序获取(“/”,(请求,请求)=>{
取('https://www.gravatar.com/avatar/fdb4d2674d818861be4a4139469ebe59?s=48&d=identicon&r=PG&f=1')
。然后(res=>res.buffer())
。然后(缓冲区=>{
res.send(`
文件
你好

`) }) }) app.listen(端口,()=>console.log(`Example app listening on port${port}!`))
理想情况下,您应该为这些映像创建一个单独的端点,并将它们缓存(在内存或硬盘驱动器中),以避免在每次需要时重新下载它们