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