- Open an image editing program, copy an image (don't copy from a browser - I'll explain why later).
- Open Firefox and go to http://imgur.com
- Press Ctrl+V
- Look with utter amazement at the image you copied before being uploaded.
I know about the HTML5 Clipboard API, that works great with Chrome. In Chrome, when you paste binary image data, the browser fires a paste
event containing event.clipboardData.types
which is equal to ['Files']
, I can therefore get my image in the clipboard with
var index = event.clipboardData.types.indexOf('Files');
if(index !== -1) {
var blob = event.clipboardData.items[index].getAsFile();
}
In Firefox, when I paste binary image data, the browser also fires a paste event, but event.clipboardData.types
is empty (has length === 0
) and event.clipboardData.getData('Files')
returns obviously ""
.
By the way, copying an image from a browser also sets a "text/html" item in clipboardData
that holds the copied <img>
element. So in those cases I could work around the problem by sending the remote url to the server, which would then download the image itself (if the server has access to the remote location, which isn't really guaranteed).
StackOverflow suggests this:
How to obtain data from clipboard in Firefox
(create a contenteditable <div>
, ask the user to paste into that and then copy the contents.)
However, imgur does not do that. How does that work?