Take advantage of the HTML5 filereader API to easily parse data from a file. Another option is to read the file into a data URL and load that instead of the regular URL.
Here is the HTML code for allowing users to load the model file:
<h1>Model File Reader</h1>
<div>
Select a model file:
<input type="file" id="fileInput">
</div>
For handling the onload event in JavaScript, use the following code:
window.onload = function() {
var fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', function(e) {
// File selection is complete, now you can read the file
var file = this.files[0];
// Set the file encoding
var encoding = 'ISO-8859-1';
// Create a file reader
var reader = new FileReader();
// Set the onload handler for the reader
reader.onload = function(e) {
var result = reader.result;
// Parse the data using the corresponding loader
loader.parse(result);
}
// Read the file as text using the reader
reader.readAsText(file, encoding);
});
}
For more information on the file reader class, you can check here.