Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know that the dragged files from specific file extension?

I'm making my own dropzone and I want to do an action while specific file extension dragging, I found that onDragEnter can't access file types, onDrop only can make that.

But I found a library that makes what I want to do, I tried hard to know from the source code how they do it but I fail. here is the link of the code

https://react-dropzone.netlify.com/#!/Accepting%20specific%20file%20types/5

like image 836
gasser mamdouh Avatar asked Oct 28 '25 06:10

gasser mamdouh


1 Answers

Actually the file type is available, I don't know how react dropzone does it, but you can access the type via DragEvent.dataTransfer.items[0].type, items is the array of items being dragged so you can access the others via items[1] etc.

$('div').on('dragover',function(e){
console.log(e.originalEvent.dataTransfer.items[0].type);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>dropzone</div>
like image 199
Musa Avatar answered Oct 31 '25 01:10

Musa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!