AAGAM JAIN
AAGAM JAIN

Reputation: 47

Pasting file not work from clipboard on react

I want to implement image upload by pasting from the clipboard.

so, I tried that get a file object from onPaste

const handlePaste = (e)=>{
   console.log(e.clipboardData);
}
<input onPaste={(e)=>handlePaste(e)} />

In console.log I don't get any data. Here is the SC for reference.

Screeenshot

How to tackle this? Is there any alternative for this so that we could get the image data and display the image using blob ?

Upvotes: 0

Views: 935

Answers (1)

Faizan Amin
Faizan Amin

Reputation: 458

You can use onPasteCapture

<input onPasteCapture={(e) => {
    console.log(e.clipboardData.files)
}} />

Upvotes: 1

Related Questions