111
parent
9e7d6d12fe
commit
53c1f4d84b
|
@ -19,12 +19,7 @@ public class UploadDataManagementMode {
|
|||
* 用于在系统中唯一标识一个工作空间,便于在不同模块和功能中引用和操作特定的工作空间
|
||||
*/
|
||||
private String workspaceId;
|
||||
/**
|
||||
* 租约的标识符
|
||||
*
|
||||
* 用于在系统中唯一标识一个租约,便于在不同模块和功能中引用和操作特定的租约
|
||||
*/
|
||||
private String LeaseId;
|
||||
|
||||
/**
|
||||
* 区域ID,用于标识不同的区域
|
||||
*/
|
||||
|
|
|
@ -28,4 +28,8 @@ public class UploadLeaseParamsMode {
|
|||
* 存储HTTP请求的目标URL,即请求的地址
|
||||
*/
|
||||
private String Url;
|
||||
|
||||
private String LeaseId;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ public class KnowledgeBaseUploadController {
|
|||
private KnowledgeBaseUploadService knowledgeBaseUploadService;
|
||||
|
||||
@PostMapping("/KnowledgeBaseUpload")
|
||||
public void uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
public String uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
String workspaceId = "llm-98lxu358qfvxdxvt";
|
||||
String categoryId = "cate_997567e8a7e94f4caab94e78c580adb4_10062067";
|
||||
knowledgeBaseUploadService.uploadDocument(file, workspaceId, categoryId);
|
||||
return knowledgeBaseUploadService.uploadDocument(file, workspaceId, categoryId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@ package com.muyu.aliyun.service;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface KnowledgeBaseUploadService {
|
||||
void uploadDocument(MultipartFile file, String workspaceId, String categoryId);
|
||||
String uploadDocument(MultipartFile file, String workspaceId, String categoryId);
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class KnowledgeBaseUploadServiceImpl implements KnowledgeBaseUploadServic
|
|||
private ReviewResolution reviewResolution;
|
||||
|
||||
@Override
|
||||
public void uploadDocument(MultipartFile file, String workspaceId, String categoryId) {
|
||||
public String uploadDocument(MultipartFile file, String workspaceId, String categoryId) {
|
||||
try {
|
||||
// 1. 保存临时文件
|
||||
File tempFile = convertMultipartFileToFile(file);
|
||||
|
@ -67,6 +67,8 @@ public class KnowledgeBaseUploadServiceImpl implements KnowledgeBaseUploadServic
|
|||
fileUploadLeaseModel.setMd5(md5);
|
||||
fileUploadLeaseModel.setSizeInBytes(String.valueOf(sizeInBytes));
|
||||
|
||||
|
||||
|
||||
UploadLeaseParamsMode leaseParams = applyLease.applyFileUploadLease(fileUploadLeaseModel);
|
||||
if (leaseParams == null) {
|
||||
throw new RuntimeException("申请文档上传租约失败");
|
||||
|
@ -87,7 +89,7 @@ public class KnowledgeBaseUploadServiceImpl implements KnowledgeBaseUploadServic
|
|||
UploadDataManagementMode uploadDataManagementMode = new UploadDataManagementMode();
|
||||
uploadDataManagementMode.setWorkspaceId(workspaceId);
|
||||
// 这里需要设置 LeaseId,假设 LeaseId 在 UploadLeaseParamsMode 中有对应的 getter
|
||||
uploadDataManagementMode.setLeaseId("");
|
||||
uploadDataManagementMode.setLeaseId(leaseParams.getLeaseId());
|
||||
AddFileResponseBodyDataMode addFileResult = addDataManagement.addFile(uploadDataManagementMode);
|
||||
if (addFileResult == null) {
|
||||
throw new RuntimeException("将文档添加至百炼的数据管理失败");
|
||||
|
@ -108,8 +110,10 @@ public class KnowledgeBaseUploadServiceImpl implements KnowledgeBaseUploadServic
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private File convertMultipartFileToFile(MultipartFile file) throws IOException {
|
||||
Path tempFilePath = Files.createTempFile(null, null);
|
||||
File tempFile = tempFilePath.toFile();
|
||||
|
|
Loading…
Reference in New Issue