分片上传校验
This commit is contained in:
parent
1b26b4c037
commit
7327cddbc1
@ -15,6 +15,7 @@ import java.io.FileNotFoundException;
|
||||
*/
|
||||
public interface ZhUploadSliceService extends IService<ZhFileMergeInfo> {
|
||||
public AjaxResult uploadSlice (MultipartFile file, String hash, String filename, Integer seq, String type);
|
||||
public AjaxResult checkMerge(String filename, String type, String hash,Integer sliceCount);
|
||||
public AjaxResult uploadMerge(String filename, String type, String hash);
|
||||
public AjaxResult downloadFile(String fileName);
|
||||
public AjaxResult getFileUrl(String fileName);
|
||||
|
@ -63,6 +63,23 @@ public class ZhUploadSliceServiceImpl extends ServiceImpl<ZhFileMergeInfoMapper,
|
||||
resp.put("msg",sliceResult.getString("msg"));
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件分片数量校验
|
||||
* @param filename 文件名
|
||||
* @param type 文件类型
|
||||
* @param hash 文件哈希值
|
||||
* @param sliceCount 分片数量
|
||||
* @return
|
||||
*/
|
||||
public AjaxResult checkMerge(String filename, String type, String hash,Integer sliceCount){
|
||||
AjaxResult resp = new AjaxResult();
|
||||
String uploadPathMerge = uploadPath+"uploadSlice/";
|
||||
JSONObject mergeResult = UploadSliceUtil.checkMerge(filename, type, hash, sliceCount, uploadPathMerge);
|
||||
resp.put("code", mergeResult.getBoolean("success") ? 200 : 500);
|
||||
resp.put("deSlice",mergeResult.getJSONArray("deSlice"));
|
||||
return resp;
|
||||
}
|
||||
/**
|
||||
* 合并文件
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.bhne.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bhne.common.utils.obs.HuaWeiOBSUtil;
|
||||
import com.bhne.common.utils.uuid.UUID;
|
||||
@ -62,6 +63,37 @@ public class UploadSliceUtil {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 文件分片数量校验
|
||||
* @param filename 文件名
|
||||
* @param type 文件类型
|
||||
* @param hash 文件哈希值
|
||||
* @param sliceCount 分片数量
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject checkMerge(String filename, String type, String hash,Integer sliceCount,String uploadPath){
|
||||
JSONObject resp = new JSONObject();
|
||||
JSONArray deSlice = new JSONArray();
|
||||
// 判断hash对应文件夹是否存在
|
||||
/*File dir = new File(uploadPath + hash);
|
||||
if (!dir.exists()) {
|
||||
resp.put("success",false);
|
||||
for(int i=1;i<=sliceCount;i++){
|
||||
deSlice.add(i);
|
||||
}
|
||||
resp.put("deSlice",deSlice);
|
||||
return resp;
|
||||
}*/
|
||||
for(int i=1;i<=sliceCount;i++){
|
||||
File slice = new File(uploadPath + hash + '/' + filename + '.' + type + i);
|
||||
if (!slice.exists()) {
|
||||
deSlice.add(i);
|
||||
}
|
||||
}
|
||||
resp.put("success",deSlice.size()>0 ? false : true);
|
||||
resp.put("deSlice",deSlice);
|
||||
return resp;
|
||||
}
|
||||
/**
|
||||
* 合并文件
|
||||
*
|
||||
@ -77,6 +109,7 @@ public class UploadSliceUtil {
|
||||
resp.put("success",false);
|
||||
resp.put("msg","上传失败");
|
||||
log.error(hash+"文件合并失败,分片目录不存在。");
|
||||
return resp;
|
||||
}
|
||||
// 这里通过FileChannel来实现信息流复制
|
||||
FileChannel out = null;
|
||||
|
Loading…
Reference in New Issue
Block a user