Code: Select all
<input id="file" type="file">
<script type="text/javascript">
(function() {
document.getElementById("file").addEventListener("change", function() {
var file = this.files[0]
, lastModifiedDate = null
;
setInterval(function() {
if(lastModifiedDate !== file.lastModifiedDate.toLocaleString()) {
lastModifiedDate = file.lastModifiedDate.toLocaleString();
console.log("file modified");
}
}, 1000);
});
})();
</script>
The problem is that when I modify the file the new modification date is not retrieved by Firefox. It keeps its initial value, which is the one retrieved when the file was opened.
I tested it in Chrome and it updates the modification date on the FILE object. Btw, reading the file periodically (using FileReader) gives the modified/new data in both Firefox and Chrome.
Is the lack of updated lastModifiedDate property intended or it is a bug/omission? Is there an alternative way to find if the file got modified (without reading its data)?
1. https://developer.mozilla.org/en-US/docs/Web/API/File/lastModifiedDate
2. https://developer.mozilla.org/en-US/docs/Web/API/File
3. https://developer.mozilla.org/en-US/docs/Web/API/FileReader