javascript – How to resolve the C:fakepath?
javascript – How to resolve the C:fakepath?
Some browsers have a security feature that prevents JavaScript from knowing your files local full path. It makes sense – as a client, you dont want the server to know your local machines filesystem. It would be nice if all browsers did this.
Use
document.getElementById(file-id).files[0].name;
instead of
document.getElementById(file-id).value
javascript – How to resolve the C:fakepath?
I use the object FileReader on the input onchange
event for your input file type! This example uses the readAsDataURL function and for that reason you should have an tag. The FileReader object also has readAsBinaryString to get the binary data, which can later be used to create the same file on your server
Example:
var input = document.getElementById(inputFile);
var fReader = new FileReader();
fReader.readAsDataURL(input.files[0]);
fReader.onloadend = function(event){
var img = document.getElementById(yourImgTag);
img.src = event.target.result;
}
Related posts on java script :
- strategies to reverse a linked list in JavaScript
- javascript – Disable Chrome strict MIME type checking
- javascript – Uncaught ReferenceError: React is not defined
- Conversion from JavaScript to Python code?
- javascript – Click events on Pie Charts in Chart.js
- javascript – Google Maps API v3: How to remove all markers?
- javascript – Jquery datatables destroy/re-create
- javascript – how to mock node-redis using jest
- javascript – Uncaught SyntaxError: Invalid or unexpected token
- javascript – Alternative to msSaveOrOpenBlob on Chrome