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