I currently have the below JS code – I’m trying to make the image that’s uploaded into my HTML upload box appear in the box once it’s been uploaded by the user, but I keep getting an error message. The error message is:
Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.
const dropArea = document.getElementById("drop-area");
const inputFile = document.getElementById("input-file");
const imageView = document.getElementById("img-view");
inputFile.addEventListener("change", uploadImage);
function uploadImage() {
let imgLink = URL.createObjectURL(inputFile.files[0]);
imageView.style.backgroundImage = `url${imgLink}`;
}
HTML for reference:
<form class="tg-form">
<div>Upload Avatar</div>
<div class="upload-container">
<label for="input-file" id="drop-area">
<input type="file" accept="image/*" id="input-file" hidden />
<div class="inner-label-container">
<div id="img-view">
<img src="assets/images/icon-upload.svg" />
</div>
<div>Drag and drop or click to upload</div>
</div>
</label>
</div>
How to fix this?