Compare commits
No commits in common. "0d1395fa4b2f00554db9ae9856780224b4f3544e" and "b04c65a949e5322047f653e46136c84a03204108" have entirely different histories.
0d1395fa4b
...
b04c65a949
@ -14,9 +14,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.imooc.utils.QcCloud;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "FileController 文件上传测试的接口")
|
||||
@RestController
|
||||
@ -42,11 +39,4 @@ public class FileController {
|
||||
|
||||
return GraceJSONResult.ok(imgUrl);
|
||||
}
|
||||
|
||||
private QcCloud qcCloud;
|
||||
@PostMapping("uploadVd")
|
||||
public GraceJSONResult uploadVd(MultipartFile file) throws Exception {
|
||||
String vdFileId = qcCloud.uploadViaTempFile(file);
|
||||
return GraceJSONResult.ok(vdFileId);
|
||||
}
|
||||
}
|
||||
|
@ -112,14 +112,6 @@
|
||||
<version>3.1.270</version>
|
||||
</dependency>
|
||||
|
||||
<!--腾讯云点播-->
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>vod_api</artifactId>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
|
@ -1,66 +0,0 @@
|
||||
package com.imooc.utils;
|
||||
import com.qcloud.vod.model.VodUploadResponse;
|
||||
import com.qcloud.vod.VodUploadClient;
|
||||
import com.qcloud.vod.model.VodUploadRequest;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
|
||||
@Component
|
||||
public class QcCloud {
|
||||
@Autowired
|
||||
private TencentCloudProperties tencentCloudProperties;
|
||||
public String getSecretId() {
|
||||
return tencentCloudProperties.getSecretId();
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return tencentCloudProperties.getSecretKey();
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return "ap-guangzhou";// 腾讯云 VOD 和 COS 使用相同区域
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String uploadViaTempFile(MultipartFile file) throws Exception {
|
||||
// 1. 获取文件扩展名
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
|
||||
// 2. 获取当前时间戳和 UUID 作为文件名
|
||||
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
||||
String uniqueFilename = "vod-" + timestamp + "-" + UUID.randomUUID().toString().replace("-", "").substring(8) + "." + extension;
|
||||
|
||||
// 3. 创建临时文件并转存
|
||||
Path tempFile = Files.createTempFile("vod-", "-" + uniqueFilename); // 创建临时文件
|
||||
file.transferTo(tempFile.toFile()); // 将文件上传内容写入临时文件
|
||||
|
||||
System.out.println("文件临时路径: " + tempFile.toString());
|
||||
|
||||
try {
|
||||
VodUploadClient client = new VodUploadClient(getSecretId(), getSecretKey());
|
||||
VodUploadRequest request = new VodUploadRequest();
|
||||
request.setMediaFilePath(tempFile.toString()); // 指定本地文件路径
|
||||
request.setProcedure("视频处理"); // 智能审核+水印
|
||||
// 4. 上传文件
|
||||
VodUploadResponse response = client.upload(getRegion(), request);
|
||||
return response.getFileId(); // 返回腾讯云 VOD 的 id
|
||||
} finally {
|
||||
// 5. 删除临时文件
|
||||
Files.deleteIfExists(tempFile);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user