浏览代码

修改上传分片的参数

zhuliu 1 年之前
父节点
当前提交
7150b07020
共有 2 个文件被更改,包括 7 次插入5 次删除
  1. 1 1
      src/api/newApi/file.js
  2. 6 4
      src/utils/model/ImportProgress/index.vue

+ 1 - 1
src/api/newApi/file.js

@@ -14,7 +14,7 @@ export default {
   },
   //上传分片
   uploadChunks(data) {
-    return axios.post('/fileManager/chunks?_=' + new Date().getTime(), data)
+    return axios.post('/fileManager/chunks', data)
   },
   /**
    * 合并分片

+ 6 - 4
src/utils/model/ImportProgress/index.vue

@@ -100,16 +100,17 @@ export default {
         
           getFileMD5(this.form.file, async (md5) => {
             this.record('文件MD5:' + md5)
-            const start = await this.$api.startChunks({md5: md5, fileName: this.form.file.name,sourceId:this.$constants.sourceId})
+            var time = new Date().getTime()
+            const start = await this.$api.startChunks({md5: md5, fileName: this.form.file.name,sourceId:this.$constants.sourceId,time:time})
             if(!start.data){
                 return
             }
             this.state = 1
-            await this.uploadChunks(fileChunks, md5, 0)
+            await this.uploadChunks(fileChunks, md5, 0,time)
             this.state = 2
             // this.record('等待服务器合并分片')
             this.recordMessage = '等待服务器合并分片'
-            const response = await this.$api.mergeChunks({ md5: md5, fileName: this.form.file.name })
+            const response = await this.$api.mergeChunks({ md5: md5, fileName: this.form.file.name,time:time })
             if(response.code != 200){
                 return
             }
@@ -131,7 +132,7 @@ export default {
       this.currentIndex += 1
       this.percentage =parseInt( this.currentIndex / this.len * 100)
     },
-    async uploadChunks(fileChunks, md5, index=0) {
+    async uploadChunks(fileChunks, md5, index=0,time) {
         for(var i = index;i<fileChunks.length;i++){
            
             await new Promise((resolve,reject) => {
@@ -139,6 +140,7 @@ export default {
                 formData.append('file', fileChunks[i].file)
                 formData.append('md5', md5)
                 formData.append('index', i)
+                formData.append('time', time)
                 formData.append('sourceId', this.$constants.sourceId)
                 // setTimeout(()=>{
                 //     const status = `将分片上传至服务器(${i + 1}/${fileChunks.length})`