上传大文件完成 速度有点慢
删除完成
This commit is contained in:
parent
7ead5d4f1a
commit
b167e904c8
@ -1,5 +1,8 @@
|
|||||||
package com.zhu.onemanager.controller.onedrive;
|
package com.zhu.onemanager.controller.onedrive;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
|
import cn.hutool.core.stream.CollectorUtil;
|
||||||
import com.zhu.onemanager.constant.FileConstant;
|
import com.zhu.onemanager.constant.FileConstant;
|
||||||
import com.zhu.onemanager.logic.impl.OneDriveItemUrlImpl;
|
import com.zhu.onemanager.logic.impl.OneDriveItemUrlImpl;
|
||||||
import com.zhu.onemanager.pojo.DriveParams;
|
import com.zhu.onemanager.pojo.DriveParams;
|
||||||
@ -12,6 +15,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ggBall
|
* @author ggBall
|
||||||
@ -84,7 +89,7 @@ public class OnedriveController {
|
|||||||
* @return com.zhu.onemanager.result.R
|
* @return com.zhu.onemanager.result.R
|
||||||
**/
|
**/
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public R upload(@RequestParam("file") MultipartFile file,String itemId) throws IOException {
|
public R uploadItem(@RequestParam("file") MultipartFile file,String itemId) throws IOException, InterruptedException {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return R.error("上传失败,请选择文件");
|
return R.error("上传失败,请选择文件");
|
||||||
}
|
}
|
||||||
@ -102,8 +107,15 @@ public class OnedriveController {
|
|||||||
} else {
|
} else {
|
||||||
return onedriveService.uploadMIniFile(uploadItem);
|
return onedriveService.uploadMIniFile(uploadItem);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/delete")
|
||||||
|
public R deleteItem(@RequestParam("itemIds") List<String> itemIds) {
|
||||||
|
if (CollUtil.isEmpty(itemIds)) {
|
||||||
|
return R.error("未选择删除文件");
|
||||||
|
}
|
||||||
|
|
||||||
|
return onedriveService.deleteItem(itemIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,4 +80,29 @@ public class OneDriveItemUrlImpl {
|
|||||||
return rootUrl + Strings.solve(url,uploadItem.getItemId(),uploadItem.getFileName());
|
return rootUrl + Strings.solve(url,uploadItem.getItemId(),uploadItem.getFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ggball
|
||||||
|
* @Description 获取删除url
|
||||||
|
* @Date 2022/1/11
|
||||||
|
* @Param driveId
|
||||||
|
* @Param itemId
|
||||||
|
* @return java.lang.String
|
||||||
|
**/
|
||||||
|
public String getDeleteUrl(String driveId,String itemId) {
|
||||||
|
String path = Strings.solve("/drives/{drive-id}/items/{item-id}", driveId, itemId);
|
||||||
|
return rootUrl + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ggball
|
||||||
|
* @Description 获取删除url
|
||||||
|
* @Date 2022/1/11
|
||||||
|
* @Param itemId
|
||||||
|
* @return java.lang.String
|
||||||
|
**/
|
||||||
|
public String getCurDeleteUrl(String itemId) {
|
||||||
|
String path = Strings.solve("/me/drive/items/{item-id}", itemId);
|
||||||
|
return rootUrl + path;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.zhu.onemanager.result.R;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface OnedriveService {
|
public interface OnedriveService {
|
||||||
|
|
||||||
@ -55,4 +56,13 @@ public interface OnedriveService {
|
|||||||
* @return com.zhu.onemanager.result.R
|
* @return com.zhu.onemanager.result.R
|
||||||
**/
|
**/
|
||||||
R multiUpload(OneDriveUploadItem uploadItem) throws IOException;
|
R multiUpload(OneDriveUploadItem uploadItem) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ggball
|
||||||
|
* @Description 删除itemId集合
|
||||||
|
* @Date 2022/1/11
|
||||||
|
* @Param [itemIds]
|
||||||
|
* @return com.zhu.onemanager.result.R
|
||||||
|
**/
|
||||||
|
R deleteItem(List<String> itemIds);
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,14 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ggBall
|
* @author ggBall
|
||||||
@ -109,8 +112,6 @@ public class OnedriveServiceImpl implements OnedriveService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public R multiUpload(OneDriveUploadItem uploadItem) throws IOException {
|
public R multiUpload(OneDriveUploadItem uploadItem) throws IOException {
|
||||||
// 初始化线程池
|
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(5);
|
|
||||||
|
|
||||||
MultipartFile file = uploadItem.getFile();
|
MultipartFile file = uploadItem.getFile();
|
||||||
byte[] bytes = file.getBytes();
|
byte[] bytes = file.getBytes();
|
||||||
@ -125,7 +126,9 @@ public class OnedriveServiceImpl implements OnedriveService {
|
|||||||
// 文件总长度
|
// 文件总长度
|
||||||
long totalLength = file.getSize();
|
long totalLength = file.getSize();
|
||||||
|
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
for (Map.Entry<int[], byte[]> entry : byteMap.entrySet()) {
|
for (Map.Entry<int[], byte[]> entry : byteMap.entrySet()) {
|
||||||
|
|
||||||
// 数据范围 [0] 起始位置 [1] 结束位置
|
// 数据范围 [0] 起始位置 [1] 结束位置
|
||||||
int[] range = entry.getKey();
|
int[] range = entry.getKey();
|
||||||
// 数据
|
// 数据
|
||||||
@ -133,14 +136,39 @@ public class OnedriveServiceImpl implements OnedriveService {
|
|||||||
// 此次传输的文件长度
|
// 此次传输的文件长度
|
||||||
int contentLength = values.length;
|
int contentLength = values.length;
|
||||||
|
|
||||||
System.out.println("range[0] = " + range[0] + "range[1] =" + range[1]);
|
|
||||||
// 调用上传接口
|
|
||||||
Dict res = GHttpUtil.put(curUploadSession, fileBytes, contentType, contentLength, totalLength, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
return R.ok(null);
|
// 调用上传接口
|
||||||
|
Dict res = GHttpUtil.put(curUploadSession, values, contentType, contentLength, totalLength, range);
|
||||||
|
System.out.println("range[0] = " + range[0] + "range[1] =" + range[1] + " res: " + res);
|
||||||
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
log.info("耗时{}秒",(end-start)/1000.0);
|
||||||
|
|
||||||
|
return R.ok("上传成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param itemIds
|
||||||
|
* @return com.zhu.onemanager.result.R
|
||||||
|
* @Author ggball
|
||||||
|
* @Description 删除itemId集合
|
||||||
|
* @Date 2022/1/11
|
||||||
|
* @Param [itemIds]
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public R deleteItem(List<String> itemIds) {
|
||||||
|
List<String> urls = new LinkedList<>();
|
||||||
|
|
||||||
|
for (String itemId : itemIds) {
|
||||||
|
urls.add(oneDriveItemUrl.getCurDeleteUrl(itemId));
|
||||||
|
}
|
||||||
|
|
||||||
|
urls.parallelStream().forEach(url -> {
|
||||||
|
GHttpUtil.delete(url);
|
||||||
|
});
|
||||||
|
|
||||||
|
return R.ok("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +27,7 @@ public class FileUtils {
|
|||||||
/**
|
/**
|
||||||
* Microsoft Graph indicates all chunks MUST be in a multiple of 320Kib (327,680 bytes).
|
* Microsoft Graph indicates all chunks MUST be in a multiple of 320Kib (327,680 bytes).
|
||||||
*/
|
*/
|
||||||
private static final Integer FRAG_SIZE = 320 * 10 * FileConstant.STANDARD_KB;
|
private static final Integer FRAG_SIZE = 192 * 320 * FileConstant.STANDARD_KB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author ggball
|
* @Author ggball
|
||||||
@ -46,6 +46,13 @@ public class FileUtils {
|
|||||||
FileUtil.writeUtf8Map(map,file, FileConstant.KV_SEPARATOR,false);
|
FileUtil.writeUtf8Map(map,file, FileConstant.KV_SEPARATOR,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ggball
|
||||||
|
* @Description 读取文件 返回map
|
||||||
|
* @Date 2022/1/11
|
||||||
|
* @Param [path, separator]
|
||||||
|
* @return java.util.Map
|
||||||
|
**/
|
||||||
public static Map readMap(String path,String separator) throws IOException {
|
public static Map readMap(String path,String separator) throws IOException {
|
||||||
File file = FileUtil.file(PathConstant.getFilePath(path));
|
File file = FileUtil.file(PathConstant.getFilePath(path));
|
||||||
|
|
||||||
@ -94,7 +101,7 @@ public class FileUtils {
|
|||||||
// 添加字节
|
// 添加字节
|
||||||
newBytes[i % FRAG_SIZE] = values[i];
|
newBytes[i % FRAG_SIZE] = values[i];
|
||||||
|
|
||||||
// 下标是4mb的倍数
|
// 下标是FRAG_SIZE的倍数
|
||||||
if ((i+1) / FRAG_SIZE > 0 && (i+1) % FRAG_SIZE == 0) {
|
if ((i+1) / FRAG_SIZE > 0 && (i+1) % FRAG_SIZE == 0) {
|
||||||
// 添加字节数组
|
// 添加字节数组
|
||||||
bytes.put(new int[]{preIndex,i},newBytes.clone());
|
bytes.put(new int[]{preIndex,i},newBytes.clone());
|
||||||
|
@ -53,17 +53,25 @@ public class GHttpUtil extends HttpUtil {
|
|||||||
public static Dict put(String url,byte[] values,String contentType,int contentLength,long totalLength,int[] range) {
|
public static Dict put(String url,byte[] values,String contentType,int contentLength,long totalLength,int[] range) {
|
||||||
HttpRequest request = HttpRequest
|
HttpRequest request = HttpRequest
|
||||||
.put(url)
|
.put(url)
|
||||||
.contentType("application/octet-stream")
|
.contentType(contentType)
|
||||||
.contentLength(contentLength)
|
.header("Content-Range","bytes " + range[0] + "-" + range[1] + "/" + totalLength) // "bytes 0-99/100"
|
||||||
|
// .contentLength(contentLength)
|
||||||
.body(values);
|
.body(values);
|
||||||
|
|
||||||
// 添加 传输指定字节的范围
|
// 添加 传输指定字节的范围
|
||||||
request.header("Content-Range","bytes " + range[0] + "-" + range[1] + "/" + totalLength); // "bytes 0-99/100"
|
|
||||||
String url1 = request.getUrl();
|
|
||||||
String res = request.execute().body();
|
String res = request.execute().body();
|
||||||
System.out.println("res = " + res);
|
|
||||||
return Dict.parse(JSONObject.parseObject(res, Map.class));
|
return Dict.parse(JSONObject.parseObject(res, Map.class));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*删除请求*/
|
||||||
|
public static Dict delete(String url) {
|
||||||
|
HttpRequest request = HttpRequest
|
||||||
|
.delete(url);
|
||||||
|
HttpResponse res = request.execute();
|
||||||
|
Dict dict = new Dict();
|
||||||
|
dict.put("status",res.getStatus());
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
20350
src/main/resources/webapp/package-lock.json
generated
20350
src/main/resources/webapp/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,7 @@
|
|||||||
"css-loader": "^0.28.11",
|
"css-loader": "^0.28.11",
|
||||||
"element-ui": "^2.0.0-rc.1",
|
"element-ui": "^2.0.0-rc.1",
|
||||||
"file-loader": "^1.1.11",
|
"file-loader": "^1.1.11",
|
||||||
|
"qs": "^6.10.3",
|
||||||
"sass-loader": "^7.1.0",
|
"sass-loader": "^7.1.0",
|
||||||
"vue": "^2.5.2",
|
"vue": "^2.5.2",
|
||||||
"vue-pdf": "^4.3.0",
|
"vue-pdf": "^4.3.0",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<div id="table">
|
<div id="table">
|
||||||
<el-row :gutter="24">
|
<el-row :gutter="24">
|
||||||
<el-col :span="1">
|
<el-col :span="1">
|
||||||
<el-button size="small" type="danger">删除</el-button>
|
<el-button size="small" type="danger" @click="deleteCheckedItems">删除</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="1">
|
<el-col :span="1">
|
||||||
<el-upload
|
<el-upload
|
||||||
@ -11,8 +11,7 @@
|
|||||||
:data="uploadExtraData"
|
:data="uploadExtraData"
|
||||||
:show-file-list="false"
|
:show-file-list="false"
|
||||||
:on-success="uploadSuccess"
|
:on-success="uploadSuccess"
|
||||||
:on-error="uploadError"
|
:on-error="uploadError">
|
||||||
:on-exceed="handleExceed">
|
|
||||||
<el-button size="small" type="primary">上传</el-button>
|
<el-button size="small" type="primary">上传</el-button>
|
||||||
<!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>-->
|
<!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>-->
|
||||||
</el-upload>
|
</el-upload>
|
||||||
@ -46,7 +45,14 @@
|
|||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
v-loading="loading"
|
v-loading="loading"
|
||||||
:data="fileList"
|
:data="fileList"
|
||||||
|
ref="multipleTable"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
>
|
>
|
||||||
|
<el-table-column
|
||||||
|
type="selection"
|
||||||
|
width="55">
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column
|
<el-table-column
|
||||||
prop="id"
|
prop="id"
|
||||||
label="id"
|
label="id"
|
||||||
@ -120,7 +126,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import qs from 'qs'
|
||||||
|
|
||||||
var env = process.env
|
var env = process.env
|
||||||
const baseUrl = env.BASE_URL === 'undefined' ? 'http://localhost:8081/' : env.BASE_URL
|
const baseUrl = env.BASE_URL === 'undefined' ? 'http://localhost:8081/' : env.BASE_URL
|
||||||
@ -145,7 +151,9 @@ export default {
|
|||||||
// 上传路径
|
// 上传路径
|
||||||
uploadUrl: baseUrl+"oneDrive/upload",
|
uploadUrl: baseUrl+"oneDrive/upload",
|
||||||
// 上传额外信息
|
// 上传额外信息
|
||||||
uploadExtraData: {}
|
uploadExtraData: {},
|
||||||
|
// 选中itemId集合
|
||||||
|
checkedItem:{}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -226,18 +234,6 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 上传相关
|
// 上传相关
|
||||||
handleRemove(file, fileList) {
|
|
||||||
console.log(file, fileList);
|
|
||||||
},
|
|
||||||
handlePreview(file) {
|
|
||||||
console.log(file);
|
|
||||||
},
|
|
||||||
handleExceed(files, fileList) {
|
|
||||||
this.$message.warning(`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
|
|
||||||
},
|
|
||||||
beforeRemove(file, fileList) {
|
|
||||||
return this.$confirm(`确定移除 ${ file.name }?`);
|
|
||||||
},
|
|
||||||
uploadSuccess(response, file, fileList) {
|
uploadSuccess(response, file, fileList) {
|
||||||
this.$message({
|
this.$message({
|
||||||
message: '上传成功',
|
message: '上传成功',
|
||||||
@ -245,6 +241,7 @@ export default {
|
|||||||
});
|
});
|
||||||
this.index()
|
this.index()
|
||||||
},
|
},
|
||||||
|
|
||||||
uploadError(err, file, fileList) {
|
uploadError(err, file, fileList) {
|
||||||
this.$message({
|
this.$message({
|
||||||
message: '上传失败',
|
message: '上传失败',
|
||||||
@ -257,6 +254,42 @@ export default {
|
|||||||
this.uploadExtraData = {"itemId":this.curItemId}
|
this.uploadExtraData = {"itemId":this.curItemId}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
deleteCheckedItems() {
|
||||||
|
// 获取项目ids
|
||||||
|
let itemIds = []
|
||||||
|
for (let checkedItem of this.checkedItem) {
|
||||||
|
itemIds.push(checkedItem.id)
|
||||||
|
}
|
||||||
|
return axios
|
||||||
|
.get(baseUrl + 'oneDrive/delete',{
|
||||||
|
params: {
|
||||||
|
itemIds: itemIds
|
||||||
|
},
|
||||||
|
paramsSerializer: params => {
|
||||||
|
return qs.stringify(params, { indices: false })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
console.log(response.data.data)
|
||||||
|
this.loading = false;
|
||||||
|
this.index()
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error)
|
||||||
|
this.index()
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/*checkBox*/
|
||||||
|
|
||||||
|
// checkbox变化时触发
|
||||||
|
handleSelectionChange(val) {
|
||||||
|
this.checkedItem = val;
|
||||||
|
},
|
||||||
|
|
||||||
// 容量转换
|
// 容量转换
|
||||||
bytesToSize (item) {
|
bytesToSize (item) {
|
||||||
var bytes = item.size
|
var bytes = item.size
|
||||||
|
Loading…
Reference in New Issue
Block a user