I'm developing a web application that kind of resembles a graph editor, which lets users insert boxes, draw connections, etc.
When trying to implement the Save and Save As feature, I stuck at how to save the files locally. I've tried creating a tags with download attribute, then triggering their click events, but it doesn't allow renaming and choosing the directory. Instead, every time the user hits Save, it starts a new download, resulting in numerous duplicates in the Downloads folder.
function downloadFile(myFileName, myContent) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(myContent));
pom.setAttribute('download', myFileName);
pom.click();
}
How I want it to work is like, for example, diagrams.net. When creating a new file using Device storage, it first launches the Save As box asking for name and directory. Afterward, when hitting Save, the already created file gets overwritten instead of downloading another version of the file.
What should I do to achieve this using Javascript?