|
|
|
@ -141,7 +141,9 @@ public class FileChunkUploadUtil { |
|
|
|
|
public void uploadChunk(MultipartFile uploadFile, SysFileChunk chunk) throws IOException { |
|
|
|
|
if (!chunksCache.containsKey(chunk.getChunkMd5())) { |
|
|
|
|
File chunkFile = new File(chunkFIleStorePath + File.separator + chunk.getChunkMd5() + ".chunk"); |
|
|
|
|
chunkFile.deleteOnExit(); |
|
|
|
|
if(chunkFile.exists()){ |
|
|
|
|
chunkFile.delete(); |
|
|
|
|
} |
|
|
|
|
uploadFile.transferTo(chunkFile); |
|
|
|
|
chunk.setChunkPath(chunkFile.getAbsolutePath()); |
|
|
|
|
chunksCache.put(chunk.getChunkMd5(), chunk); |
|
|
|
@ -161,18 +163,20 @@ public class FileChunkUploadUtil { |
|
|
|
|
if (!parent.exists()) { |
|
|
|
|
parent.mkdirs(); |
|
|
|
|
} |
|
|
|
|
targetFile.deleteOnExit(); |
|
|
|
|
if(targetFile.exists()){ |
|
|
|
|
targetFile.delete(); |
|
|
|
|
targetFile.createNewFile(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<SysFileChunk> chunks = new ArrayList<>(chunksCache.values()); |
|
|
|
|
chunks.sort((o1, o2) -> (int) (o1.getChunkIndex() - o2.getChunkIndex())); |
|
|
|
|
FileOutputStream outputStream = new FileOutputStream(targetFile, true); |
|
|
|
|
try (FileOutputStream outputStream = new FileOutputStream(targetFile, true)) { |
|
|
|
|
for (SysFileChunk chunk : chunks) { |
|
|
|
|
File chunkFile = new File(chunk.getChunkPath()); |
|
|
|
|
FileUtils.copyFile(chunkFile, outputStream); |
|
|
|
|
} |
|
|
|
|
outputStream.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 删除分片缓存文件,该方法为递归删除
|
|
|
|
|
FileUtil.del(chunkFIleStorePath); |
|
|
|
|