input file gets the local path and base64 path of the selected image
local path:
myHeadFile: function (e) { // This is the onchange event of the input file const file = e.srcElement.files[ 0 ] const imgURL = window.URL.createObjectURL(file) // imgURL is the local path of your image, two can solve the problem }
base64:
// Get the file var file = $( " #imgForm " ).find( " input " )[ 0 ].files[ 0 ]; // Create an object to read the file var reader = new FileReader(); // Create a file to read related variables var imgFile; reader.onload=function(e) { alert( ' File read complete ' ); imgFile = e.target.result; console.log(imgFile); $("#imgContent").attr('src', imgFile); }; // Officially read the file reader.readAsDataURL(file);