A mini tricks between input field and img tag in html to show an image.
- Use
event.clipboardDataorevent.originalEvent.clipboardData. event.clipboardDataorevent.originalEvent.clipboardDatacontains items if they have. If they contain, writevar items = (event.clipboardData || event.originalEvent.clipboardData).items;.- Now, you have
items. Itsitems, you can do a loop 💁♂️. You can see each element by index of that loopitems[index]. - We need only file item from
items[index]. So, you may do a check like thisif (item.kind === 'file'). - Get the blob data of this file item by writing
var blob = item.getAsFile();. - As it is a file, you have to read the file item. To read a file item, Javascript has a class
FileReader(). Writevar reader = new FileReader();. - How can you see If a file is not loaded 🤫?. Write
reader.onload = function (event) {};. - Inside the above
onloadfunction, you can writedocument.getElementById("pastedImage").src = event.target.result;of your image html tag<img id="pastedImage"/>. - Then copy image and paste image and BOOM!!!.
