Node.js nodejs fs读取文件如何给出https路径

Node.js nodejs fs读取文件如何给出https路径,node.js,Node.js,文件系统读取文件,确切的https路径如何给定和读取文件 var path_name : https://example.s3.ap-south-1.amazonaws.com/kc/insp_report1.pdf var http = require('http'); var fs = require('fs'); http.createServer(function (req, res) { //Open a file on t

文件系统读取文件,确切的https路径如何给定和读取文件

 var path_name : https://example.s3.ap-south-1.amazonaws.com/kc/insp_report1.pdf
    var http = require('http');
        var fs = require('fs');
        http.createServer(function (req, res) {
          //Open a file on the server and return its content:
          fs.readFile(path_name, function(err, data) {
            res.writeHead(200, {'Content-Type': 'application/pdf'});
            res.write(data);
            return res.end();
          });
        }).listen(8080);
我的错误是它也会占用我的系统路径

{错误:enoint:没有这样的文件或目录,请打开 'C:\Users\example\Desktop\react\manyuBackEnd\https:example.s3.ap-south-1.amazonaws.comkcinsp_report1.pdf'


fs
代表,用于操作驻留在主机上的文件-除非您可以直接访问驻留在不同服务器上的文件(例如,两台服务器共享同一网络),否则不能使用
fs
读取驻留在不同服务器上的文件


您需要从服务器发出GET请求,通过或第三方库(如或)下载文件。我假设您希望从路径名中的链接下载pdf,然后将pdf保存到本地文件。您希望发出GET请求(如James suggest)请求数据。您必须创建写流然后处理来自get请求的响应

var file = fs.createWriteStream('file_path');
https.get('your url', (res) => {
   res.on('data', (chunk) => { file.write(chunk); });
   res.on('end', () => { file.end() }
});

试着看看这个答案是否有帮助:var path_name='https://example.s3.ap-south-1.amazonaws.com/kc/insp_report1.pdf'不,不是working@Anil我的回答有助于解决你的问题吗?