新增:回传文件到本地磁盘
This commit is contained in:
@@ -19,6 +19,7 @@ import io.swagger.v3.oas.annotations.media.Content;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@@ -27,6 +28,14 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -466,5 +475,60 @@ public class DataFileController implements IDataFeignClient {
|
|||||||
return IDataFileService.onlyOfficeCallback(callbackData);
|
return IDataFileService.onlyOfficeCallback(callbackData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* flowable 节点文件回传本地磁盘
|
||||||
|
* @param fileId 绝对路径拼接成成临时碎片目录,filename 文件名称,absoluteFilePath:文件的绝对路径,不带文件名称
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping ("/flowableUpFileToLocal")
|
||||||
|
public ResponseEntity<String> uploadChunk(
|
||||||
|
@RequestParam String fileId,
|
||||||
|
@RequestParam int chunkIndex,
|
||||||
|
@RequestParam String absoluteFilePath,
|
||||||
|
HttpServletRequest request) throws IOException {
|
||||||
|
// chunk 路径:/data/upload/chunks/{fileId}/{chunkIndex}.part
|
||||||
|
Path normalize = Paths.get(absoluteFilePath).toAbsolutePath().normalize();
|
||||||
|
Path chunkDir = normalize.resolve(fileId).normalize();
|
||||||
|
Files.createDirectories(chunkDir);
|
||||||
|
Path chunkPath = chunkDir.resolve(chunkIndex + ".temp");
|
||||||
|
try (InputStream in = request.getInputStream();
|
||||||
|
OutputStream out = Files.newOutputStream(chunkPath,
|
||||||
|
StandardOpenOption.CREATE,
|
||||||
|
StandardOpenOption.WRITE)) {
|
||||||
|
in.transferTo(out);
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping ("/flowableUpFileToLocalMerge")
|
||||||
|
public ResponseEntity<String> mergeChunks(
|
||||||
|
@RequestParam String fileId,
|
||||||
|
@RequestParam int totalChunks,
|
||||||
|
@RequestParam String absoluteFilePath,
|
||||||
|
@RequestParam String filename) throws IOException {
|
||||||
|
Path targetDir = Paths.get(absoluteFilePath).toAbsolutePath().normalize();
|
||||||
|
Path chunkDir = targetDir.resolve(fileId);
|
||||||
|
Files.createDirectories(targetDir);
|
||||||
|
Path targetFile = targetDir.resolve(filename);
|
||||||
|
try (OutputStream out = Files.newOutputStream(
|
||||||
|
targetFile,
|
||||||
|
StandardOpenOption.CREATE,
|
||||||
|
StandardOpenOption.WRITE)) {
|
||||||
|
for (int i = 0; i < totalChunks; i++) {
|
||||||
|
Path chunk = chunkDir.resolve(i + ".temp");
|
||||||
|
try (InputStream in = Files.newInputStream(chunk)) {
|
||||||
|
in.transferTo(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 合并完删除分片
|
||||||
|
Files.walk(chunkDir)
|
||||||
|
.sorted(Comparator.reverseOrder())
|
||||||
|
.forEach(path -> {
|
||||||
|
try { Files.delete(path); } catch (Exception ignored) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
return ResponseEntity.ok("SUCCESS:" + targetFile.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -120,4 +120,6 @@ minio:
|
|||||||
security:
|
security:
|
||||||
whitelist:
|
whitelist:
|
||||||
paths:
|
paths:
|
||||||
- /data/previewImage
|
- /data/previewImage
|
||||||
|
- /data/flowableUpFileToLocal
|
||||||
|
- /data/flowableUpFileToLocalMerge
|
||||||
Reference in New Issue
Block a user