Enable copy and paste files in dropzone.js

后端 未结 3 1270
庸人自扰
庸人自扰 2020-12-14 21:13

I am using dropzone.js. I want to implement the \"Copy & Paste\" feature in it.

What I tried is:

Inside dropzone.js:<

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 22:07

    If you don't want to use other JS libraries, you can integrate dropzone with a paste event fairly easily by retrieving the data as a file from the paste event:

    // create dropzone however you wish
    var myDropzone = new Dropzone("div#element", { url: "/path/to/upload"});
    // add paste event listener to the page
    document.onpaste = function(event){
      var items = (event.clipboardData || event.originalEvent.clipboardData).items;
      for (index in items) {
        var item = items[index];
        if (item.kind === 'file') {
          // adds the file to your dropzone instance
          myDropzone.addFile(item.getAsFile())
        }
      }
    }
    

提交回复
热议问题