Reputation: 23
I'm constructing the URL dynamically pointing to local IP address in my action class,
Below is the URL constructed:
<a file='#' onClick=window.open('file://154.66.111.123/SD/SPRD/index.htm','_self') >Click Here </a>
The above URL works fine in IE, but in chrome i could not able to access that URL, below is the exception noticed on browser console:
Not allowed to load local resource:file://154.66.111.123/SD/SPRD/index.htm
How can i access local file system from chrome?Please suggest. Thanks.
Upvotes: 2
Views: 10496
Reputation: 996
You can't access a file like that for security reasons. But you can access a file without uploading it using javascript. one way to do that is using file input field.
onchange
event listener to the inputURL.createObjectURL
functionsample code
let input = document.querySelector("#input");
input.addEventListener("change", (e)=>{
let file = input.files[0];
let url = URL.createObjectURL(file); // A valid URL that you can use on the page
})
Upvotes: 3