第一:該插件必需要導入的css,js有css
<link rel="stylesheet" href="${ctxPath}/static/css/file/bootstrap.min.css">html
<link rel="stylesheet" href="${ctxPath}/static/css/file/style.css">jquery
<link rel="stylesheet" href="${ctxPath}/static/css/file/jquery.fileupload.css">git
<link rel="stylesheet" href="${ctxPath}/static/css/file/jquery.fileupload-ui.css">github
<script src="${ctxPath}/static/js/file/jquery.iframe-transport.js"></script>ajax
<script src="${ctxPath}/static/js/file/jquery.fileupload.js"></script>spring
<script src="${ctxPath}/static/js/file/jquery.fileupload-process.js"></script>json
<script src="${ctxPath}/static/js/file/jquery.fileupload-image.js"></script>bootstrap
<script src="${ctxPath}/static/js/file/jquery.fileupload-audio.js"></script>跨域
<script src="${ctxPath}/static/js/file/jquery.fileupload-video.js"></script>
<script src="${ctxPath}/static/js/file/jquery.fileupload-validate.js"></script>
<script src="${ctxPath}/static/js/file/jquery.fileupload-ui.js"></script>
<script src="${ctxPath}/static/js/file/main.js"></script>
<script src="${ctxPath}/static/js/file/cors/jquery.xdr-transport.js"></script>
第二:要先了解spring boot和guns框架,而後找到視頻上傳管理點擊添加,出現文件上傳和一些其餘你須要的字段,下面的頁面使用Beetl引擎和HTML5 內聯框架iFrame
@layout("/common/_container.html"){ <div class="float-e-margins"><!--ibox--> <div class=""><!--ibox-content--> <div class="container"><!--form-horizontal--> <input type="hidden" id="id" value=""> <form id = "fileupload" method = "POST" enctype="multipart/form-data" action="/videoUpload" target="hidden_frame"> <div class="row fileupload-buttonbar col-lg-7"> <div class="col-lg-7"> 類型 <input id="videoType" name="videoType"/> <br/> 簡介 <input id="videoIntroduce" name="videoIntroduce"/> <br/> 類別 <input id="videoClass" name="videoClass"/> <br/> <span class="btn btn-success fileinput-button"> <i class="glyphicon glyphicon-plus"></i> <span>添加文件...</span> <input type="file" name="files" multiple> </span> <button type="submit" class="btn btn-primary start"> <i class="glyphicon glyphicon-upload"></i> <span>開始上傳</span> </button> <button type="reset" class="btn btn-warning cancel"> <i class="glyphicon glyphicon-ban-circle"></i> <span>取消上傳</span> </button> <button type="button" class="btn btn-danger delete"> <i class="glyphicon glyphicon-trash"></i> <span>刪除</span> </button> <input type="checkbox" class="toggle"> <!--全局文件處理狀態--> <span class="fileupload-process"></span> </div> <div class="fileupload-progress fade" > <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100"> <div class="progress-bar progress-bar-success" style="width:0%;"></div> </div> <div class="progress-extended"> </div> </div> </div> <!--列出可用於上傳/下載的文件的表格--> <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table> <div class="row btn-group-m-t"> <div class="col-sm-10"> <#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="VideoInfoDlg.addSubmit()"/> <#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="VideoInfoDlg.close()"/> </div> </div> </form> </div> </div> </div>
<!--顯示可用於上傳的文件模板--> <script id="template-upload" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %} <tr class="template-upload fade"> <td> <span class="preview"></span> </td> <td> <p class="name">{%=file.name%}</p> <strong class="error text-danger"></strong> </td> <td> <p class="size">Processing...</p> <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div> </td> <td> {% if (!i && !o.options.autoUpload) { %} <button class="btn btn-primary start" disabled> <i class="glyphicon glyphicon-upload"></i> <span>Start</span> </button> {% } %} {% if (!i) { %} <button class="btn btn-warning cancel"> <i class="glyphicon glyphicon-ban-circle"></i> <span>Cancel</span> </button> {% } %} </td> </tr> {% } %} </script>
<!--提供可下載的文件的模板--> <script id="template-download" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %} <tr class="template-download fade"> <td> <span class="preview"> {% if (file.thumbnailUrl) { %} <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a> {% } %} </span> </td> <td> <p class="name"> {% if (file.url) { %} <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a> {% } else { %} <span>{%=file.name%}</span> {% } %} </p> {% if(file=="" || file==null){ %} {% if (file.error) { %} <div><span class="label label-danger">請選擇文件</span> {%=file.error%}</div> {% } %} {% } %} {% if(file.success){ %} <div><span class="label label-success">上傳成功</span> {%=file.success%}</div> {% } %} </td> <td> <span class="size">{%=o.formatFileSize(file.size)%}</span> </td> <td> {% if (file.deleteUrl) { %} <button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}> <i class="glyphicon glyphicon-trash"></i> <span>刪除</span> </button> <input type="checkbox" name="delete" value="1" class="toggle"> {% } else { %} <button class="btn btn-warning cancel"> <i class="glyphicon glyphicon-ban-circle"></i> <span>取消</span> </button> {% } %} </td> </tr> {% } %} </script>
<script src="${ctxPath}/static/modular/system/video/video_info.js"></script> <script src="${ctxPath}/static/js/file/jquery.iframe-transport.js"></script> <script src="${ctxPath}/static/js/file/jquery.fileupload.js"></script> <script src="${ctxPath}/static/js/file/jquery.fileupload-process.js"></script> <script src="${ctxPath}/static/js/file/jquery.fileupload-image.js"></script> <script src="${ctxPath}/static/js/file/jquery.fileupload-audio.js"></script> <script src="${ctxPath}/static/js/file/jquery.fileupload-video.js"></script> <script src="${ctxPath}/static/js/file/jquery.fileupload-validate.js"></script> <script src="${ctxPath}/static/js/file/jquery.fileupload-ui.js"></script> <script src="${ctxPath}/static/js/file/main.js"></script> <script src="${ctxPath}/static/js/file/cors/jquery.xdr-transport.js"></script> @}
**第三:在jquery-file-upload插件中有一個main.js是須要改動的,當函數不做爲對象的屬性被調用時,也就是咱們常說的普通函數方式,此時的this老是指向全局對象,在ECMAScript4的strict模式下,這種狀況下的this已經被規定爲不會指向全局對象,而是undifined,就是下面的"user strict"。重點在"#fileupload" id要和表單from的id一致 **
$(function () { 'use strict'; // Initialize the jQuery File Upload widget: //初始化jQuery文件上傳小部件: $('#fileupload').fileupload({ // Uncomment the following to send cross-domain cookies: //爲true取消如下內容發送跨域cookie: xhrFields: {withCredentials: false}, url: '/videoUpload' }); // Enable iframe cross-domain access via redirect option: //經過重定向選項啓用iframe跨域訪問: /*$('#fileupload').fileupload( 'option', 'redirect', window.location.href.replace( /\/[^\/]*$/, '/cors/result.html?%s' ) );*/ console.log(window.location.hostname); if (window.location.hostname === 'blueimp.github.io') { // Demo settings: //演示設置: /*$('#fileupload').fileupload('option', { /!*url: '//jquery-file-upload.appspot.com/',*!/ url: '/videoUpload', // Enable image resizing, except for Android and Opera, //啓用圖像調整,除了Android和Opera // which actually support image resizing, but fail to //這實際上支持圖像調整,但不能 // send Blob objects via XHR requests: //經過XHR請求發送Blob對象: disableImageResize: /Android(?!.*Chrome)|Opera/ .test(window.navigator.userAgent), maxFileSize: 999000, acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i });*/ // Upload server status check for browsers with CORS support: //爲帶有CORS支持的瀏覽器上傳服務器狀態檢查: /*if ($.support.cors) { $.ajax({ url: '/videoUpload', type: 'HEAD' }).fail(function () { $('<div class="alert alert-danger"/>') .text('Upload server currently unavailable - ' + new Date()) .appendTo('#fileupload'); }); }*/ } else { // Load existing files: $('#fileupload').addClass('fileupload-processing'); $.ajax({ // Uncomment the following to send cross-domain cookies: //爲true取消如下內容發送跨域cookie xhrFields: {withCredentials: false}, url: $('#fileupload').fileupload('option', 'url'), dataType: 'json', context: $('#fileupload')[0] }).always(function () { $(this).removeClass('fileupload-processing'); }).done(function (result) { $(this).fileupload('option', 'done') .call(this, $.Event('done'), {result: result}); }); } });