Víctor Gómez
Víctor Gómez

Reputation: 722

Upload images from Clipboard

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?

Upvotes: 2

Views: 234

Answers (1)

kukis
kukis

Reputation: 4644

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).

Upvotes: 2

Related Questions