1

I am looking into solution when users can copy paste any file in order to upload it.

I am using onPaste and when I console log on the event.clipboardData.files, I see that all the details within files is converted image even though I try to upload pdf or any other files.

However,

const text = (e['originalEvent'] || e).clipboardData.getData('text/plain');

that does gives me proper file name. but event.clipboardData.files holds image type, which messes up uploading file other than images.

*HTML*

<div onPaste={handlePaste}>

</div>

*JS*


const handlePaste = (e) => {
  console.log(e.clipboardData.files)
}

e above have this object within event.clipboardData.files


{
   lastModified: 1675788471866
   name: "image.png",
   size: 0,
   type: "image/png",
   webkitRelativePath: "",
}

Any help is appreciated. Thank you

pnaika
  • 31
  • 4

0 Answers0