MozillaZine

Static lastModifiedDate on open local file (File API)

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
ppath
 
Posts: 1
Joined: August 10th, 2015, 5:19 am

Post Posted August 10th, 2015, 5:58 am

I want to find when a local file opened in a browser has been modified. I use the File API to periodically check the lastModifiedDate property of the File object corresponding to the opened file. Below I post the code:

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

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 1 guest