在一个我要借助Cefsharp自动化的网站上,我需要提供一个JavaScript File.File()。我要提供的文件已本地保存,可以是pdf,office文档或图像等任何文件。就CefSharp而言,我已经实现了ISchemeHandlerFactory和ResourceHandler添加了test://方案,例如,我已经成功添加了这样的JS文件。
var head = document.head;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'test://local/folder/mytest.js';
head.appendChild(script);
根据API创建我需要的文件
位-ArrayBuffer,ArrayBufferView,Blob或DOMString对象的数组-或任何此类对象的混合。这是编码为UTF-8的文件内容。
所以我有test://的方案,可以给我一个本地文件,我需要在javascript中使用什么才能将其保存到文件中?
答案 0 :(得分:0)
我努力了。我首先尝试了访存,但这不会让我使用自定义方案。所以我不得不使用XMLHttpRequest
(function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var contentType = xhttp.getResponseHeader("Content-Type");
var file = new File([this.response],'3Markets.xlsx', {type: contentType,});
//use my new file etc
}
};
xhttp.open('GET', 'test://local/folder/3Markets.xlsx', true);
xhttp.responseType = "arraybuffer";
xhttp.send();
})()
我唯一要解决的问题就是我目前必须打电话
CefCommandLineArgs.Add("disable-web-security", "disable-web-security")
我将不得不环顾一下如何在不禁用网络安全性的情况下实现这一目标,或者最终在这里提出问题。