Upload-fine-uploader

fine-uploader:轻松创建功能强大,优雅且灵活的文件上传组件

使用fine-uploader也很简单,它分为纯JavaScript和jQuery依赖两种

1.下面是使用jquery的html代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- jQuery
    ====================================================================== -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

    <!-- Fine Uploader New/Modern CSS file
    ====================================================================== -->
    <link href="client/fine-uploader-new.css" rel="stylesheet">

    <!-- Fine Uploader jQuery JS file
    ====================================================================== -->
    <script src="client/jquery.fine-uploader.js"></script>

    <!-- Fine Uploader Thumbnails template w/ customization
    ====================================================================== -->
    <script type="text/template" id="qq-template-manual-trigger">
        <div class="qq-uploader-selector qq-uploader" qq-drop-area-text="Drop files here">
            <div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
                <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
            </div>
            <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
                <span class="qq-upload-drop-area-text-selector"></span>
            </div>
            <div class="buttons">
                <div class="qq-upload-button-selector qq-upload-button">
                    <div>Select files</div>
                </div>
                <button type="button" id="trigger-upload" class="btn btn-primary">
                    <i class="icon-upload icon-white"></i> Upload
                </button>
            </div>
            <span class="qq-drop-processing-selector qq-drop-processing">
                <span>Processing dropped files...</span>
                <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
            </span>
            <ul class="qq-upload-list-selector qq-upload-list" aria-live="polite" aria-relevant="additions removals">
                <li>
                    <div class="qq-progress-bar-container-selector">
                        <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
                    </div>
                    <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
                    <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
                    <span class="qq-upload-file-selector qq-upload-file"></span>
                    <span class="qq-edit-filename-icon-selector qq-edit-filename-icon" aria-label="Edit filename"></span>
                    <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
                    <span class="qq-upload-size-selector qq-upload-size"></span>
                    <button type="button" class="qq-btn qq-upload-cancel-selector qq-upload-cancel">Cancel</button>
                    <button type="button" class="qq-btn qq-upload-retry-selector qq-upload-retry">Retry</button>
                    <button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">Delete</button>
                    <span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
                </li>
            </ul>

            <dialog class="qq-alert-dialog-selector">
                <div class="qq-dialog-message-selector"></div>
                <div class="qq-dialog-buttons">
                    <button type="button" class="qq-cancel-button-selector">Close</button>
                </div>
            </dialog>

            <dialog class="qq-confirm-dialog-selector">
                <div class="qq-dialog-message-selector"></div>
                <div class="qq-dialog-buttons">
                    <button type="button" class="qq-cancel-button-selector">No</button>
                    <button type="button" class="qq-ok-button-selector">Yes</button>
                </div>
            </dialog>

            <dialog class="qq-prompt-dialog-selector">
                <div class="qq-dialog-message-selector"></div>
                <input type="text">
                <div class="qq-dialog-buttons">
                    <button type="button" class="qq-cancel-button-selector">Cancel</button>
                    <button type="button" class="qq-ok-button-selector">Ok</button>
                </div>
            </dialog>
        </div>
    </script>

    <style>
        #trigger-upload {
            color: white;
            background-color: #00ABC7;
            font-size: 14px;
            padding: 7px 20px;
            background-image: none;
        }

        #fine-uploader-manual-trigger .qq-upload-button {
            margin-right: 15px;
        }

        #fine-uploader-manual-trigger .buttons {
            width: 36%;
        }

        #fine-uploader-manual-trigger .qq-uploader .qq-total-progress-bar-container {
            width: 60%;
        }
    </style>

    <title>Fine Uploader Manual Upload Trigger Demo</title>
</head>
<body>
    <!-- Fine Uploader DOM Element
    ====================================================================== -->
    <div id="fine-uploader-manual-trigger"></div>

    <!-- Your code to create an instance of Fine Uploader and bind to the DOM/template
    ====================================================================== -->
    <script>
    var uploader = new qq.FineUploader({
        template: 'qq-template-manual-trigger',
        debug: false,
        thumbnails: {
            placeholders: {
                waitingPath: 'client/placeholders/waiting-generic.png',
                notAvailablePath: 'client/placeholders/not_available-generic.png'
            }
        },
        element: document.getElementById('fine-uploader-manual-trigger'),
        request: {
            endpoint: 'uploads',
            params:{},
            paramsInBody:false
        },
        deleteFile: {
            enabled: true,
            endpoint: '',
            method:"DELETE",
            params:{}
        },
        autoUpload: false,
        retry: {
            enableAuto: true,
            autoAttemptDelay:5,
            maxAutoAttempts:3
        },
        button:{
        },
        disableCancelForFormUploads:false,
        formatFileName:function(filename){

        },
        maxConnections:3,
        multiple:true,
        warnBeforeUnload:true,
        blobs:{
            defaultName:filename
        },
        camera:{
            button:htmlbutton,
            iso:false
        },
        chunking:{
            concurrent:{
                enabled:false
            },
            enabled:false,
            partSize:2000000,
            paramNames:{
                chunkSize:chunkSize,
                partByteOffset:partByteOffset,
                partIndex:partIndex,
                totalParts:totalParts
            },
            success:{
                endpoint:endpoint,
                headers:function(fileId) { return null },
                jsonPayload:false,
                method:"POST",
                params:function(fileId) { return null },
                resetOnStatus:status
            }
        },
        cors:{
            allowXdr:false,
            expected:false,
            sendCredentials:false
        },
        extraButtons:{
            folders:false
        },
        form:{
            element:element,
            autoUpload:false
        },
        messages:{
            emptyError:"{file} is empty, please select files again without it.",
            sizeError:"{file} is too large, maximum file size is {sizeLimit}.",
            tooManyItemsError:"Too many items ({netItems}) would be uploaded. Item limit is {itemLimit}.",
            typeError:"{file} has an invalid extension. Valid extension(s): {extensions}."
        },
        paste:{
            defaultName:defaultName
        },
        resume:{
            customKeys:function(fileId) { return [] },
            enabled:false,
            paramNames:{
                resuming:"qqresume"
            },
            recordsExpireIn:7
        },
        scaling:{
        },
        session:{
        },
        text:{
        },
        validation:{
            acceptFiles:"",//以逗号分隔的有效MIME类型列表
            allowedExtensions:['jpeg', 'jpg', 'gif', 'png'],//在此处指定文件有效文件扩展名以限制上传到特定类型。
            allowEmpty:false,//允许文件大小为0字节
            itemLimit:0,//可以在此会话中上载的最大项目数。在达到此限制后,将拒绝添加或重试的所有项目
            minSizeLimit:0,//项目的最小允许大小(以字节为单位)。
            image:{
                maxHeight:0,
                maxWidth:0,
                minHeight:0,
                minWidth:0
            }
        },
        workarounds:{
        },
        callbacks:{
            onSubmit:  function(id,  fileName)  {
                console.log(fileName);
            },
            onUpload:function (id, fileName) {
                uploader.cancelAll();
            },
            onAutoRetry:  function(id,  fileName,retryNum)  {
                console.log(fileName);
            },
            onCancel:  function(id,  fileName)  {
                console.log(fileName);
            },
            onComplete:  function(id,  fileName,responseJSON)  {
                console.log(fileName);
            },
            onAllComplete:  function(ids ) {
                console.log(ids);
            },
            onDelete:  function(id)  {
                console.log(id);
            },
            onDeleteComplete:  function(id,  xhr,isError)  {
                console.log(isError);
            },
            onError:  function(id,  fileName,errorReason,xhr)  {
                console.log(errorReason);
            },
            onManualRetry:  function(id,  fileName)  {
                console.log(fileName);
            },
            onPasteReceived:  function(blob)  {
                console.log(blob);
            },
            onProgress:  function(id,  fileName,uploadedBytes,totalBytes)  {
                console.log(totalBytes);
            }
        }
    });
    </script>
</body>
</html>
uploader是一个对象,有方法,属性,和定义回调函数,结构如下:
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,616评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,020评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,078评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,040评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,154评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,265评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,298评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,072评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,491评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,795评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,970评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,654评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,272评论 3 318
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,985评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,223评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,815评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,852评论 2 351

推荐阅读更多精彩内容