2

I am working with Vaadin and I want to upload an image from client's clipboard to the server.

I tried:

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

try {
    BufferedImage image = 
            (BufferedImage)clipboard.getData(DataFlavor.imageFlavor);                     
}    
catch(UnsupportedFlavorException ufe) {
    ufe.printStackTrace();
}        
catch(IOException ioe) {
    ioe.printStackTrace();
}

However, this code only works in the local machine.

How can I allow users to upload their clipboard's image?

André Schild
  • 4,592
  • 5
  • 28
  • 42
Víctor Gómez
  • 724
  • 6
  • 23
  • I think this is not possible so far, cause Vaadin doesn't support it right now. You can write your own addon which handles this over JavaScript etc. – marc3l Dec 09 '15 at 12:40
  • I'm not even sure any web browser allows you to access the clipboard – André Schild Dec 09 '15 at 14:17
  • I also remember something similar to what @AndréSchild is saying due to security issue. Nonetheless, things may have changed since I last looked, and as per MarcelHöll's suggestion, [this question](http://stackoverflow.com/questions/6333814/how-does-the-paste-image-from-clipboard-functionality-work-in-gmail-and-google-c) seems to suggest otherwise and may give you a starting point – Morfic Dec 09 '15 at 14:28

1 Answers1

2

You can't get clients clipboard content (even using JavaScript) due to security concerns. There is however way to handle onpaste event on a client side and pass the data to the server side. This requires writing some code in JavaScript (you can always browse through Vaadin addons - maybe someone already has done that and shared with others).

kukis
  • 4,489
  • 6
  • 27
  • 50