Reputation: 722
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
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