Dropzone js - Drag n Drop file from same page

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

I am using Dropzone plugin for multiple files drag n drop functionality. Drag n drop works fine when I am uploading pictures from my laptop / desktop.

My question is - how can I drag n drop images into dropzone from same page. Lets say I have a dropzone div and I am having another div having multiple images. I want to drag n drop those images into dropzone.

回答1:

this.on("drop", function(event) {   var imageUrl = event.dataTransfer.getData('URL');   var fileName = imageUrl.split('/').pop();    // set the effectAllowed for the drag item   event.dataTransfer.effectAllowed = 'copy';    function getDataUri(url, callback) {     var image = new Image();      image.onload = function() {       var canvas = document.createElement('canvas');       canvas.width = this.naturalWidth; // or 'width' if you want a special/scaled size       canvas.height = this.naturalHeight; // or 'height' if you want a special/scaled size        canvas.getContext('2d').drawImage(this, 0, 0);        // Get raw image data       // callback(canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, ''));        // ... or get as Data URI       callback(canvas.toDataURL('image/jpeg'));     };      image.setAttribute('crossOrigin', 'anonymous');     image.src = url;   }    function dataURItoBlob(dataURI) {     var byteString,         mimestring      if (dataURI.split(',')[0].indexOf('base64') !== -1) {       byteString = atob(dataURI.split(',')[1])     } else {       byteString = decodeURI(dataURI.split(',')[1])     }      mimestring = dataURI.split(',')[0].split(':')[1].split(';')[0]      var content = new Array();     for (var i = 0; i 

http://codepen.io/BartSitek/pen/ZeMGjV

  • Convert Data URI to Blob
  • Add Blob to Dropzone form


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!