I am new to javascript and I am currently having problem with one of my projects which includes viewing of an image from the root folder of the website. Here is my current code:
var reader = new FileReader();
reader.onload = function(event){
var dataUri = event.target.result,
img = document.createElement("img");
img.src = dataUri;
document.body.appendChild(img);
};
reader.onerror = function(event){
console.log("File could not be read: " + event.target.error.code);
};
reader.readAsDataURL("/uploads/extras/item_a/image1.png");
That's my code and it doesnt show anything. And in my console it gives me an error or Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
GET data: net::ERR_INVALID_URL@NewToJS/uploads/extras/item_a/image1.png? What's your folder structure like?readeris not happy with theurl. Try hard coding the entire path to the file i.ehttp://example.com/uploads/extras/item_a/image1.pngto rule out other issues.Failed to load resource: net::ERR_INVALID_URL@0019