CNode
查看回复

回复 (2)

C
chyingp#1·8 年前

不行。res.download(path) 只能针对的是本地文件。如果是远程文件,可以参考如下思路。

createReadStreamOfRemoteFile(url).pipe(res); // createReadStreamOfRemoteFile 自行实现

G
grass0916#2·8 年前

@chyingp 前辈提供的方向很好,我这边做了一个简易实例供楼主参考看看:

const request = require('request');
const http = require('http');

const url = 'https://o4j806krb.qnssl.com/public/images/cnodejs_light.svg';

const app = http.createServer((req, res) =>
    request.get(url).pipe(res)
);
app.listen(3000);
参与回复
登录后即可参与回复。登录