Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste image from the clipboard #732

Open
rsedykh opened this issue Mar 17, 2020 · 1 comment
Open

Paste image from the clipboard #732

rsedykh opened this issue Mar 17, 2020 · 1 comment

Comments

@rsedykh
Copy link
Member

rsedykh commented Mar 17, 2020

Summary

I want to open the uploader and just paste an image from the clipboard.

Basic example

They all are the same, take twitter.com for example.

Motivation

Saves time and adds convenience.

@optlsnd
Copy link
Contributor

optlsnd commented Nov 24, 2020

@rsedykh I solved it this way

const widget = uploadcare.Widget("[role=uploadcare-uploader]");

widget.onDialogOpen((dialog) => {
  function uploadFromClipboard(e) {
    let data = e.clipboardData;
    if (!!data && !!data.items.length) {
      // check if clipboard data is image
      if (data.items[0].type.indexOf("image") != 0) {
        alert("No image in the clipboard");
        return;
      }
      let blob = e.clipboardData.items[0].getAsFile();
      dialog.addFiles("object", [blob]);
    }
  }
  window.addEventListener("paste", uploadFromClipboard);
});

https://codepen.io/optlsnd/pen/KKMOOVb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants