HTML Paste Clipboard Image to File Input

It’s pretty straightforward. Just catch paste event on window object and put all the files you got from it to the <input> tag.

const form = document.getElementById("new_document_attachment");
const fileInput = document.getElementById("document_attachment_doc");

fileInput.addEventListener('change', () => {
  form.submit();
});

window.addEventListener('paste', e => {
  fileInput.files = e.clipboardData.files;
});
<form id="new_document_attachment" method="post" enctype="multipart/form-data">
  <div class="actions"><input type="submit" name="commit" value="Submit" /></div>
  <input type="file" name="document_attachment_doc" id="document_attachment_doc" />
</form>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)