Transfer (paste) files from the clipboard to a file input?

Asked

Viewed 222 times

0

I got the following input archival:

<input class="botao" @change="carregarFoto" type="file" name="photo" accept="image/*">
          <img :src="foto" style="width:192px;height:108px;" />


carregarFoto (e) {
  var arquivo = e.target.files
  if (!arquivo[0]) {
    return
  }
  var data = new FormData()
  data.append('media', arquivo[0])
  var reader = new FileReader()
  reader.onload = (e) => {
    this.foto = e.target.result
  }
  reader.readAsDataURL(arquivo[0])
}

And I want when I select it and press the keys ctrl + v the image I am in the clipboard is inserted into that input. It is possible to do this??

Note: I am using Vuejs

  • 3

    Here is the link to the solution you need: https://stackoverflow.com/questions/8000420/force-paste-event-to-encode-images-in-base64.

  • Very good, please add as an answer so that I can accept and if someone looks for the same question can find the solution

  • You can post it, I don’t have time to write a full answer, but I’m glad I could help.

  • Okay, I’ll write you an answer, if you feel the need to edit, feel free...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.