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

大文件增加请求头

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