Skip to content

Instantly share code, notes, and snippets.

@pavelk2
Created February 2, 2014 14:47
Show Gist options
  • Save pavelk2/8769436 to your computer and use it in GitHub Desktop.
Save pavelk2/8769436 to your computer and use it in GitHub Desktop.
$("body").bind("paste", function(ev) {
var $this = $(this);
var original = ev.originalEvent;
var file = original.clipboardData.items[0].getAsFile();
var reader = new FileReader();
reader.onload = function (evt) {
var result = evt.target.result;
var result = evt.target.result;
var arr = result.split(",");
var clip_data = arr[1]; // raw base64
var contentType = arr[0].split(";")[0].split(":")[1];
notificationShow('Uploading an image from clipboard','constant',0);
// this needs to post to a server route that can accept raw base64 content and save to a file
$.post(settings.uploadImageURL, {
contentType: contentType,
data: clip_data
},function(data){
var image = new Image();
if (data.id>0){
image.init(data);
image.display();
notificationShow('Image '+data.title+' is uploaded','instant');
}else{
notificationShow(data.details,'instant');
}
});
};
reader.readAsDataURL(file);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment