0

Making possibility to upload files to the site but in such a way that folders cannot be uploaded. Wrote a function that checks it.

function notADirectory(maybeFile) {    // maybeFile ~ new File()
    if (maybeFile.type !== '') return true;
    const reader = new FileReader()
    reader.onloadend = () => !(reader.error && 
        (reader.error.name === 'NotFoundError' || reader.error.name === 'NotReadableError'))
    reader.readAsBinaryString(maybeFile)
}

But there is a text.psd photoshop file and for some reason js does not see the type in it - it is empty. Because of this, the function does not work properly.

Is there any other proper way to check file on directory?

Adding directory="" webkitdirectory="" into html input is not suitable because there is also possibility to add files on site with Ctrl + V and dragging it on page

gnd20032
  • 11
  • 2
  • Does `` not work? Otherwise you are probably out of luck. See this answer https://stackoverflow.com/questions/25016442/how-to-distinguish-if-a-file-or-folder-is-being-dragged-prior-to-it-being-droppe – nlta Jul 09 '22 at 19:26
  • @nlta `` won't work because of dragging file on page. But maybe I can give access to user to upload folder but then "unpack" it? – gnd20032 Jul 09 '22 at 19:38

0 Answers0