SpringBoot WebUploader大文件分片上传
Posted 盲目的拾荒者
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot WebUploader大文件分片上传相关的知识,希望对你有一定的参考价值。
后端技术:SpringBoot2.x
页面:freemarker
webuploader:http://fex.baidu.com/webuploader/getting-started.html
1.application.properties
server.port=9999
spring.freemarker.suffix=.html
#上传文件存放目录
xdja.upload.file.path=/home/xdja/
#临时文件存放目录
xdja.upload.file.path.temp=/home/temp
##最大上传文件
spring.servlet.multipart.max-file-size=3072MB
spring.servlet.multipart.max-request-size=3072MB
2.前端代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>隔离交换系统解密</title>
<link rel="stylesheet" type="text/css" href="themes/bootstrap.min.css"/>
<link rel="stylesheet" href="themes/webuploader.css">
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript" src="script/webuploader.js"></script>
<!--layer弹出框-->
<link rel="stylesheet" href="script/layer/mobile/need/layer.css">
<script type="text/javascript" src="script/layer/layer.js"></script>
<style type="text/css">
.wu-example {
width: 847px;
position: relative;
padding: 45px 15px 15px;
margin: 0 auto;
background-color: #fafafa;
box-shadow: inset 0 3px 6px rgba(0, 0, 0, .05);
border-color: #e5e5e5 #eee #eee;
border-style: solid;
border-width: 1px 0;
}
#picker {
display: inline-block;
line-height: 1.428571429;
vertical-align: middle;
margin: 0 12px 0 0;
}
</style>
</head>
<body>
<div class="alert alert-success" role="alert" style="text-align: center;font-size: 18px;">隔离交换系统可视化解密</div>
<div id="uploader" class="wu-example">
<!--用来存放文件信息-->
<div id="thelist" class="uploader-list"></div>
<div class="btns">
<div id="picker">选择文件</div>
<button id="ctlBtn" class="btn btn-default">开始上传</button>
</div>
<p>
<span>上传所用时间:</span>
<span id="useTime">0</span>s
</p>
</div>
<script type="text/javascript">
var $list = $("#thelist");
var $btn = $("#ctlBtn");
var state = ‘pending‘; // 上传文件初始化
var timer;
var fileArray = [];
var uploader = WebUploader.create({
// swf文件路径
/* swf: BASE_URL + ‘/js/Uploader.swf‘,*/
// 文件接收服务端。
server: ‘upload‘,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建,可能是input元素,也可能是flash.
pick: ‘#picker‘,
// 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
resize: false,
duplicate: true,
chunked: true,
threads: 5,
chunkSize: 10485760,
formData: {
guid: ""
}
});
//点击上传之前调用的方法
uploader.on("uploadStart", function (file) {
var guid = WebUploader.Base.guid();
var paramOb = {"guid": guid, "filedId": file.source.ruid}
uploader.options.formData.guid = guid;
fileArray.push(paramOb);
});
// 当有文件被添加进队列的时候
uploader.on(‘fileQueued‘, function (file) {
$list.append(‘<div id="‘ + file.id + ‘" class="item">‘ +
‘<h4 class="info">‘ + file.name + ‘</h4>‘ +
‘<p class="state">等待上传...</p>‘ +
‘</div>‘);
});
// 文件上传过程中创建进度条实时显示。
uploader.on(‘uploadProgress‘, function (file, percentage) {
var $li = $(‘#‘ + file.id),
$percent = $li.find(‘.progress .progress-bar‘);
// 避免重复创建
if (!$percent.length) {
$percent = $(‘<div class="progress progress-striped active">‘ +
‘<div class="progress-bar" role="progressbar" style="width: 0%">‘ +
‘</div>‘ +
‘</div>‘).appendTo($li).find(‘.progress-bar‘);
}
$li.find(‘p.state‘).text(‘上传中‘);
$percent.css(‘width‘, percentage * 100 + ‘%‘);
});
//文件成功、失败处理
uploader.on(‘uploadSuccess‘, function (