使用javascript打开文件内容
我有一个这样的物体使用javascript打开文件内容,javascript,node.js,facebook-javascript-sdk,facebook-ads-api,Javascript,Node.js,Facebook Javascript Sdk,Facebook Ads Api,我有一个这样的物体 { id: "114898379136253" leadgen_export_csv_url: "https://www.facebook.com/ads/lead_gen/export_csv/?id=379136253&type=form&source_type=graph_api", locale: "en_US" name: "Untitled form 11/7/2017" status: "ACTIVE" } 我想
{
id: "114898379136253"
leadgen_export_csv_url: "https://www.facebook.com/ads/lead_gen/export_csv/?id=379136253&type=form&source_type=graph_api",
locale: "en_US"
name: "Untitled form 11/7/2017"
status: "ACTIVE"
}
我想获取文件内容,用来自此文件的线索填充我的数据库
在我的例子中,我还需要处理CORS,因为它是一个外部URL,但我需要在这个解决方案中得到一些帮助,在缓冲区中转换并读取缓冲区?或者存在更好的解决方案
function loadFile(file) {
var xhr = new XMLHttpRequest();
xhr.open('GET', file, true);
xhr.withCredentials = false;
xhr.responseType = 'blob';
xhr.onload = function (e) {
var reader = new FileReader();
reader.readAsDataURL(this.response);
reader.onload = function (e) {
console.log('DataURL:', e.target.result);
};
};
xhr.send();
}
DataURL:
在控制台日志中,返回一个Base64,并对Base64结果进行解码,它会返回一个网页,但不是文件。您想要这个,但您尝试了什么?@tadman请求打开文件。我更新了问题代码,使问题变得更好。@tadman更新了一些我到目前为止得到的更多信息。