前端多文件拖拽上传(可上传文件夹)

html代码:

<form action="lib/winui/js/dataTest.json" class="dropzone needsclick dz-clickable" id="demo-upload">
    <div class="dz-message needsclick" id="myId"></div>
</form>

js代码:

$(function () {
            (function () {
                var a, b, c, d, e, f, g, h, i, j = [].slice, k = function (a, b) {
                    function c() {
                        this.constructor = a;
                    }

                    for (var d in b) l.call(b, d) && (a[d] = b[d]);
                    return c.prototype = b.prototype, a.prototype = new c, a.__super__ = b.prototype, a
                }, l = {}.hasOwnProperty;
                h = function () {
                }, b = function () {
                    function a() {
                    }

                    return a.prototype.addEventListener = a.prototype.on, a.prototype.on = function (a, b) {
                        return this._callbacks = this._callbacks || {}, this._callbacks[a] || (this._callbacks[a] = []), this._callbacks[a].push(b), this
                    }, a.prototype.emit = function () {
                        var a, b, c, d, e, f;
                        if (d = arguments[0], a = 2 <= arguments.length ? j.call(arguments, 1) : [], this._callbacks = this._callbacks || {}, c = this._callbacks[d]) for (e = 0, f = c.length; e < f; e++) b = c[e], b.apply(this, a);
                        return this
                    }, a.prototype.removeListener = a.prototype.off, a.prototype.removeAllListeners = a.prototype.off, a.prototype.removeEventListener = a.prototype.off, a.prototype.off = function (a, b) {
                        var c, d, e, f;
                        if (!this._callbacks || 0 === arguments.length) return this._callbacks = {}, this;
                        if (!(c = this._callbacks[a])) return this;
                        if (1 === arguments.length) return delete this._callbacks[a], this;
                        for (d = e = 0, f = c.length; e < f; d = ++e) if (c[d] === b) {
                            c.splice(d, 1);
                            break
                        }
                        return this
                    }, a
                }(), a = function (a) {
                    function d(a, b) {
                        var c, f, g;
                        if (this.element = a, this.version = d.version, this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, ""), this.clickableElements = [], this.listeners = [], this.files = [], "string" == typeof this.element && (this.element = document.querySelector(this.element)), !this.element || null == this.element.nodeType) throw new Error("Invalid dropzone element.");
                        if (this.element.dropzone) throw new Error("Dropzone already attached.");
                        if (d.instances.push(this), this.element.dropzone = this, c = null != (g = d.optionsForElement(this.element)) ? g : {}, this.options = e({}, this.defaultOptions, c, null != b ? b : {}), this.options.forceFallback || !d.isBrowserSupported()) return this.options.fallback.call(this);
                        if (null == this.options.url && (this.options.url = this.element.getAttribute("action")), !this.options.url) throw new Error("No URL provided.");
                        if (this.options.acceptedFiles && this.options.acceptedMimeTypes) throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
                        this.options.acceptedMimeTypes && (this.options.acceptedFiles = this.options.acceptedMimeTypes, delete this.options.acceptedMimeTypes), null != this.options.renameFilename && (this.options.renameFile = function (a) {
                            return function (b) {
                                return a.options.renameFilename.call(a, b.name, b)
                            }
                        }(this)), this.options.method = this.options.method.toUpperCase(), (f = this.getExistingFallback()) && f.parentNode && f.parentNode.removeChild(f), !1 !== this.options.previewsContainer && (this.options.previewsContainer ? this.previewsContainer = d.getElement(this.options.previewsContainer, "previewsContainer") : this.previewsContainer = this.element), this.options.clickable && (!0 === this.options.clickable ? this.clickableElements = [this.element] : this.clickableElements = d.getElements(this.options.clickable, "clickable")), this.init()
                    }

                    var e, f;
                    return k(d, a), d.prototype.Emitter = b, d.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "addedfiles", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached", "queuecomplete"], d.prototype.defaultOptions = {
                        url: null,
                        method: "post",
                        withCredentials: !1,
                        timeout: 3e4,
                        parallelUploads: 2,
                        uploadMultiple: !1,
                        maxFilesize: 256,
                        paramName: "file",
                        createImageThumbnails: !0,
                        maxThumbnailFilesize: 10,
                        thumbnailWidth: 120,
                        thumbnailHeight: 120,
                        thumbnailMethod: "crop",
                        resizeWidth: null,
                        resizeHeight: null,
                        resizeMimeType: null,
                        resizeQuality: .8,
                        resizeMethod: "contain",
                        filesizeBase: 1e3,
                        maxFiles: null,
                        params: {},
                        headers: null,
                        clickable: !0,
                        ignoreHiddenFiles: !0,
                        acceptedFiles: null,
                        acceptedMimeTypes: null,
                        autoProcessQueue: !0,
                        autoQueue: !0,
                        addRemoveLinks: !1,
                        previewsContainer: null,
                        hiddenInputContainer: "body",
                        capture: null,
                        renameFilename: null,
                        renameFile: null,
                        forceFallback: !1,
                        dictDefaultMessage: "Drop files here to upload",
                        dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
                        dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
                        dictFileTooBig: "File is too big ({
  {filesize}}MiB). Max filesize: {
  {maxFilesize}}MiB.",
                        dictInvalidFileType: "You can't upload files of this type.",
                        dictResponseError: "Server responded with {
  {statusCode}} code.",
                        dictCancelUpload: "Cancel upload",
                        dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
                        dictRemoveFile: "Remove file",
                        dictRemoveFileConfirmation: null,
                        dictMaxFilesExceeded: "You can not upload any more files.",
                        dictFileSizeUnits: {tb: "TB", gb: "GB", mb: "MB", kb: "KB", b: "b"},
                        init: function () {
                            return h
                        },
                        accept: function (a, b) {
                            return b()
                        },
                        fallback: function () {
                            var a, b, c, e, f, g;
                            for (this.element.className = this.element.className + " dz-browser-not-supported", f = this.element.getElementsByTagName("div"), b = 0, c = f.length; b < c; b++) a = f[b], /(^| )dz-message($| )/.test(a.className) && (e = a, a.className = "dz-message");
                            return e || (e = d.createElement('<div class="dz-message"><span></span></div>'), this.element.appendChild(e)), g = e.getElementsByTagName("span")[0], g && (null != g.textContent ? g.textContent = this.options.dictFallbackMessage : null != g.innerText && (g.innerText = this.options.dictFallbackMessage)), this.element.appendChild(this.getFallbackForm())
                        },
                        resize: function (a, b, c, d) {
                            var e, f, g;
                            if (e = {
                                srcX: 0,
                                srcY: 0,
                                srcWidth: a.width,
                                srcHeight: a.height
                            }, f = a.width / a.height, null == b && null == c ? (b = e.srcWidth, c = e.srcHeight) : null == b ? b = c * f : null == c && (c = b / f), b = Math.min(b, e.srcWidth), c = Math.min(c, e.srcHeight), g = b / c, e.srcWidth > b || e.srcHeight > c) if ("crop" === d) f > g ? (e.srcHeight = a.height, e.srcWidth = e.srcHeight * g) : (e.srcWidth = a.width, e.srcHeight = e.srcWidth / g); else {
                                if ("contain" !== d) throw new Error("Unknown resizeMethod '" + d + "'");
                                f > g ? c = b / f : b = c * f
                            }
                            return e.srcX = (a.width - e.srcWidth) / 2, e.srcY = (a.height - e.srcHeight) / 2, e.trgWidth = b, e.trgHeight = c, e
                        },
                        transformFile: function (a, b) {
                            return (this.options.resizeWidth || this.options.resizeHeight) && a.type.match(/image.*/) ? this.resizeImage(a, this.options.resizeWidth, this.options.resizeHeight, this.options.resizeMethod, b) : b(a)
                        },
                        previewTemplate: '<div class="dz-preview dz-file-preview">\n  <div class="dz-image"><img data-dz-thumbnail /></div>\n  <div class="dz-details">\n    <div class="dz-size"><span data-dz-size></span></div>\n    <div class="dz-filename"><span data-dz-name></span></div>\n  </div>\n  <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>\n  <div class="dz-error-message"><span data-dz-errormessage></span></div>\n  <div class="dz-success-mark">\n    <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">\n      <title>Check</title>\n      <defs></defs>\n      <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">\n        <path d="M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" stroke-opacity="0.198794158" stroke="#747474" fill-opacity="0.816519475" fill="#FFFFFF" sketch:type="MSShapeGroup"></path>\n      </g>\n    </svg>\n  </div>\n  <div class="dz-error-mark">\n    <svg width="54px" height="54px" viewBox="0 0 54 54" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">\n      <title>Error</title>\n      <defs></defs>\n      <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">\n        <g id="Check-+-Oval-2" sketch:type="MSLayerGroup" stroke="#747474" stroke-opacity="0.198794158" fill="#FFFFFF" fill-opacity="0.816519475">\n          <path d="M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z" id="Oval-2" sketch:type="MSShapeGroup"></path>\n        </g>\n      </g>\n    </svg>\n  </div>\n</div>',
                        drop: function (a) {
                            return this.element.classList.remove("dz-drag-hover")
                        },
                        dragstart: h,
                        dragend: function (a) {
                            return this.element.classList.remove("dz-drag-hover")
                        },
                        dragenter: function (a) {
                            return this.element.classList.add("dz-drag-hover")
                        },
                        dragover: function (a) {
                            return this.element.classList.add("dz-drag-hover")
                        },
                        dragleave: function (a) {
                            return this.element.classList.remove("dz-drag-hover")
                        },
                        paste: h,
                        reset: function () {
                            return this.element.classList.remove("dz-started")
                        },
                        addedfile: function (a) {
                            var b, c, e, f, g, h, i, j, k, l, m, n, o;
                            if (this.element === this.previewsContainer && this.element.classList.add("dz-started"), this.previewsContainer) {
                                for (a.previewElement = d.createElement(this.options.previewTemplate.trim()), a.previewTemplate = a.previewElement, this.previewsContainer.appendChild(a.previewE
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
分片与并发结合 将一个大文件分割成多块 并发上传 极大地提高大文件上传速度 当网络问题导致传输错误时 只需要重传出错分片 而不是整个文件 另外分片传输能够更加实时的跟踪上传进度 预览 压缩 支持常用图片格式jpg jpeg gif bmp png预览与压缩 节省网络数据传输 解析jpeg中的meta信息 对于各种orientation做了正确的处理 同时压缩后上传保留图片的所有原始meta数据 多途径添加文件 支持文件多选 类型过滤 拖拽 文件&文件 图片粘贴功能 粘贴功能主要体现在当有图片数据在剪切板中时(截屏工具如QQ Ctrl + ALT + A 网页中右击图片点击复制) Ctrl + V便可添加此图片文件 HTML5 & FLASH 兼容主流浏览器 接口一致 实现了两套运行时支持 用户无需关心内部用了什么内核 同时Flash部分没有做任何UI相关的工作 方便不关心flash的用户扩展和自定义业务需求 MD5秒传 当文件体积大 量比较多时 支持上传前做文件md5值验证 一致则可直接跳过 如果服务端与前端统一修改算法 取段md5 可大大提升验证性能 耗时在20ms左右 易扩展 可拆分 采用可拆分机制 将各个功能独立成了小组件 可自由搭配 采用AMD规范组织代码 清晰明了 方便高级玩家扩展 ">分片与并发结合 将一个大文件分割成多块 并发上传 极大地提高大文件上传速度 当网络问题导致传输错误时 只需要重传出错分片 而不是整个文件 另外分片传输能够更加实时的跟踪上传进度 预览 压缩 支持常 [更多]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值