阿里云IMM智能媒体文件预览
1,导入IMM的依赖<!--阿里云IMM需要的包--><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId>&...
·
1,导入IMM的依赖
<!--阿里云IMM需要的包-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-imm</artifactId>
<version>1.14.0</version>
</dependency>
2,使用阿里云帐号的accessKeyId,secret才能够使用阿里云Java依赖
#IMM智能媒体管理
imm:
accessKeyId:
secret:
regionId:
projectName:
3,文档的预览是文件是存储在阿里云oss上面,IMM通过文档转换,把转换后的文件再存回oss,然后通过前端引擎去访问oss上的文件
@Override
public String findImm_pathByFile_path(String file_path) throws ClientException, UnsupportedEncodingException {
String find_path = cloudDiskMapper.findImm_pathByFile_path(file_path);
if (find_path!=null) {
return find_path;
}else{
IAcsClient client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId,secret));
String DecodeFile_path = URLDecoder.decode(file_path,"utf-8");
String[] split = DecodeFile_path.split("/");
String file_name = split[split.length-1];
// 创建文档转换异步请求任务
CreateOfficeConversionTaskRequest req = new CreateOfficeConversionTaskRequest();
req.setProject(projectName);
// 设置待转换对文件OSS路径
req.setSrcUri(DecodeFile_path.replace(OLDCHAR,NEWCHAR));
System.err.println(DecodeFile_path.replace(OLDCHAR,NEWCHAR));
// 设置文件输出格式为 vector
req.setTgtType("vector");
// 设置转换后的输出路径
req.setTgtUri(NEWURL+file_name);
System.err.println(NEWURL+file_name);
CreateOfficeConversionTaskResponse res = client.getAcsResponse(req);
String taskId = res.getTaskId();
// 获取文档转换任务结果,最多轮询 30 次
// 每次轮询的间隔为 1 秒
GetOfficeConversionTaskRequest getOfficeConversionTaskRequest = new GetOfficeConversionTaskRequest();
getOfficeConversionTaskRequest.setProject(projectName);
getOfficeConversionTaskRequest.setTaskId(taskId);
String imm_path = IMMURL+file_name;
cloudDiskMapper.addImm_path(file_path,imm_path);
return imm_path;
}
}
更多推荐
所有评论(0)