1
我正试图将相对文件地址加载到以前由文件读取器使用的函数中。在网站上,我有一个按钮,可以让你选择本地文件加载到图形渲染器。我想用url来相对地访问这些文件,但我无法弄清楚如何将它们绑定到一个文件对象。我一直在使用this mozilla文档来试图弄明白。使用JavaScript文件构造函数将相关文件传入函数
这里是最初使用的代码:
// function that takes file input and renders the image
function readFiles(){
// Deal with file input
if (window.File && window.FileReader && window.FileList && window.Blob) {
var file1 = document.getElementById('fileinput').files[0];
var file2 = document.getElementById('fileinput').files[1];
// Call the file analyzer
fileAnalyzer(file1, file2);
} else {
alert('The File APIs are not fully supported by your browser.');
}
}
这里是我想更新代码:
// load cube button
var loadcube = document.getElementById('loadcube');
loadcube.onclick = function(evt) {
var file1 = new File([], "Object files/cube3.coor");
var file2 = new File([], "Object files/cube3.poly");
fileAnalyzer(file1, file2);
}
只是为了澄清,你要加载存在的网站上到内存中的文件? –