从网络URL读取文件

时间:2019-07-19 04:13:24

标签: typescript

我想读取我放入S3存储桶中并公开访问的文件。使用s3,我得到文件的URL:https://tlc-test-public.s3-ap-northeast-1.amazonaws.com/public/member_id/xxx.txt。当我尝试读取此文件时,出现错误:

  

错误:ENOENT:没有此类文件或目录,请打开'https://tlc-test-public.s3-ap-northeast-1.amazonaws.com/public/member_id/xxx.txt'

const url = new URL('https://tlc-test-public.s3-ap-northeast-1.amazonaws.com/public/member_id/xxx.txt');
let stream = fs.createReadStream(url.href);

var reader = rd.createInterface({input: stream });
var lineArray: string[] = new Array;
reader.on('line', (memberId: string) => {
    lineArray.push(memberId);
    console.log(memberId);
});

我希望它能读取文本文件并在控制台中逐行打印。

0 个答案:

没有答案