I am having an issue with changing a file name.
The main issue I am having is when the user takes a picture from an iPhone. iOS names all just captured photos image.jpg. I am trying to give the user a chance to change the file name or do something programmatically, like "image (1).jpg".
I am looking for some advice on renaming files in JS or some other idea on how to handle preventing users from uploading a file with the same name.
function processSelectedFiles(fileInput) {
var files = fileInput.files;
var div = document.getElementById("fileList");
for (var i = 0; i < files.length; i++) {
var newFileName = prompt("Filename " + files[i].name,files[i].name);
if (newFileName!== null){
files[i].name=newFileName;
}
div.innerText += files[i].name;
}
}
<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/File/name -->
<input type="file" multiple onchange="processSelectedFiles(this)">
</br>
File Name:
</br>
<div id="fileList"></div>