Commit fcebe14c authored by 以墨为白's avatar 以墨为白 🎧

大文件增加请求头

parent a9b3ffeb
......@@ -21,6 +21,7 @@
import $ from "jquery";
import WebUploader from "webuploader";
import "webuploader/dist/webuploader.css";
import { ACCESS_TOKEN, ACCESS_USER, HTTP_STATUS } from "../../constant/user";
export default {
props: ['fileType'],
data() {
......@@ -29,6 +30,10 @@ export default {
};
},
mounted() {
let headers_target = {
'x-requested-with': 'XMLHttpRequest'
};
headers_target[ACCESS_TOKEN] = sessionStorage.getItem("token");
var _self = this;
//必须先注销原来的,否则服务会执行多次
WebUploader.Uploader.unRegister("uploadBigFile");
......@@ -62,6 +67,7 @@ export default {
type: "POST",
url: "api/rest/file/bigFile/check",
async: false,
headers: headers_target,
data: {
fileMd5: val,
},
......@@ -125,6 +131,7 @@ export default {
$.ajax({
type: "POST",
url: "api/rest/file/bigFile/merge",
headers: headers_target,
data: {
fileName: file.name,
fileMd5: file.md5,
......@@ -172,11 +179,13 @@ export default {
/**
* 当某个文件的分块在发送前触发,主要用来询问是否要添加附带参数,大文件在开起分片上传的前提下此事件可能会触发多次。
*/
uploader.onUploadBeforeSend = function (obj, data) {
//console.log("onUploadBeforeSend");
uploader.onUploadBeforeSend = function (obj, data, headers) {
//增加请求参数
var file = obj.file;
data.md5 = file.md5 || "";
data.uid = file.uid;
//增加请求token
$.extend(headers, headers_target);
};
/**
* 上传过程中,一直会执行该方法
......@@ -252,18 +261,19 @@ export default {
list-style: none;
margin: 10px 0px;
.el-progress{
.el-progress {
width: 95%;
margin-top: 3px;
.el-progress-bar{
.el-progress-bar__outer{
.el-progress-bar {
.el-progress-bar__outer {
height: 12px !important;
}
}
}
}
.startUpload{
.startUpload {
margin-top: 5px;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment