Allow me to explain the issue I'm facing. To give you some context, I've been working on a forum web application. Lately, I've been trying to enable users to choose a photo from their local file system during sign up. The idea is that once a user selects an image, it should be read using the FileReader API in client-side JavaScript. Then, the selected image URL should be set as the value of the file input before submitting the form.
It's important to note that my goal is not to directly upload the file as a separate image, but rather to store the data URL in my database. While many suggest using Multer for file uploads, I've already made significant progress and pushed changes to my GitHub repository. Thus, installing new npm packages is not an option at this point.
The main issue I'm encountering is that the value of the input does not change, and the uploaded URL only shows the name of the image file (for example, shark.jfif). Despite searching online, I haven't found a solution yet. Below is my current client-side JavaScript code:
const file = document.querySelector('input[type="file"]').files[0];
const fReader = new FileReader();
const imgName = fReader.readAsDataURL(file);
document.querySelector('input[type="file"]').value = imgName.result;
Ideally, I would like to use an event listener to monitor when the input file value changes. However, I'm unsure about which event would be most suitable. Using the submit event is not ideal since the code execution takes some time, and by the time the form is submitted, only the filename is saved in the database. As of now, the value remains unchanged with my existing code.