vrm360 icon indicating copy to clipboard operation
vrm360 copied to clipboard

Loading a local file

Open jumpjack opened this issue 3 years ago • 0 comments

How can I load a file from local file system using the new INPUT tag with type=FILE, which allows user to select a local file?

Get file from user:

<input type="file" id="myFile" name = "myFile" accept=".wrl" ><br>

Bind event to file selector:

const fileSelector = document.getElementById('myFile');
	fileSelector .addEventListener('change', (event) => {
		loadFile(event.target.files[0])
	});

Read file from local disk:


function loadFile(fileHandler) {
	const reader = new FileReader();
	reader.addEventListener('load', (event) => {
		rawFileContents = event.target.result;	
	});
	reader.readAsArrayBuffer(fileHandler);
}

jumpjack avatar Jul 14 '22 12:07 jumpjack