Skip to content

Instantly share code, notes, and snippets.

@ThomRoman
Forked from magemore/example.js
Created May 21, 2022 22:21
Show Gist options
  • Save ThomRoman/d89ad6a84c20df7d26aabbaa9724d781 to your computer and use it in GitHub Desktop.
Save ThomRoman/d89ad6a84c20df7d26aabbaa9724d781 to your computer and use it in GitHub Desktop.

Revisions

  1. @magemore magemore created this gist Aug 10, 2016.
    29 changes: 29 additions & 0 deletions example.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    function uploadFile(file) {
    var formData = new FormData();
    formData.append("userfile", file);
    var request = new XMLHttpRequest();
    request.onload = function () {
    if (request.status == 200) {
    document.location.href='/';
    } else {
    alert('Error! Upload failed');
    }
    };
    request.open("POST", "/compose/send");
    request.send(formData);
    }

    $("body").bind('paste', function(je){
    var e = je.originalEvent;
    for (var i = 0; i < e.clipboardData.items.length; i++) {
    var item = e.clipboardData.items[i];
    console.log('Item: ' + item.type);
    if (item.type.indexOf('image') != -1) {
    //item.
    uploadFile(item.getAsFile());
    } else {
    // ignore not images
    console.log('Discarding not image paste data');
    }
    }
    });