记得上下班打卡 | git大法好,push需谨慎

Commit ad534d28 authored by jiangxiulong's avatar jiangxiulong

阿里云上传增加视频截取帧数

parent 641e7db6
......@@ -25,6 +25,8 @@ public class UploadVo implements Serializable {
private String fileName;
@ApiModelProperty(value = "上传后的地址")
private String ossPath;
@ApiModelProperty(value = "视频截帧图片文件地址")
private String videoImg;
@ApiModelProperty(value = "文件类型")
private String contentType;
@ApiModelProperty(value = "文件大小")
......
......@@ -27,6 +27,7 @@ public class PlatformOssFiles implements Serializable ,Cloneable {
private String ossFilesId;
private String fileName;
private String ossPath;
private String videoImg;
private String contentType;
private Integer size;
private String md5str;
......
......@@ -969,27 +969,6 @@ CREATE TABLE `kylin_zhengzai_app_versions`
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT '正在现场app版本控制';
drop TABLE if exists `platform_oss_files`;
create table platform_oss_files
(
`mid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`oss_files_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'oss_files_id',
`file_name` varchar(255) NOT NULL DEFAULT '' COMMENT '源文件名称',
`content_type` varchar(255) NOT NULL DEFAULT '' COMMENT '文件类型',
`size` int NOT NULL DEFAULT 0 COMMENT '文件大小',
`md5str` varchar(255) NOT NULL DEFAULT '' COMMENT 'md5值判断文件是否相同',
`oss_path` varchar(255) NOT NULL DEFAULT '' COMMENT '文件地址(阿里oss)',
`buck_type` tinyint NOT NULL DEFAULT '0' COMMENT 'buck_type',
`uploader_uid` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人id',
`uploader_name` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人姓名',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY `kylin_oss_files_id_index` (`oss_files_id`),
PRIMARY KEY (`mid`)
) ENGINE = InnoDB
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT '阿里云OSS上传记录';
drop TABLE if exists `admin_upush`;
CREATE TABLE `admin_upush`
(
......
drop TABLE if exists `platform_oss_files`;
create table platform_oss_files
(
`mid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`oss_files_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'oss_files_id',
`file_name` varchar(255) NOT NULL DEFAULT '' COMMENT '源文件名称',
`content_type` varchar(255) NOT NULL DEFAULT '' COMMENT '文件类型',
`size` int NOT NULL DEFAULT 0 COMMENT '文件大小',
`md5str` varchar(255) NOT NULL DEFAULT '' COMMENT 'md5值判断文件是否相同',
`oss_path` varchar(255) NOT NULL DEFAULT '' COMMENT '文件地址(阿里oss)',
`buck_type` tinyint NOT NULL DEFAULT '0' COMMENT 'buck_type',
`uploader_uid` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人id',
`uploader_name` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人姓名',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY `kylin_oss_files_id_index` (`oss_files_id`),
PRIMARY KEY (`mid`)
) ENGINE = InnoDB
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT '阿里云OSS上传记录';
alter table platform_oss_files add video_img varchar(255) NOT NULL DEFAULT '' COMMENT '视频截帧图片文件地址(阿里oss)' after oss_path;
\ No newline at end of file
......@@ -29,6 +29,8 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.Formatter;
import java.util.List;
......@@ -53,6 +55,8 @@ public class AlOssController {
private String accessKeyId;
@Value("${liquidnet.al-oss.accessKeySecret}")
private String accessKeySecret;
@Value("${liquidnet.al-oss.imgUrl}")
private String imgUrl;
@Autowired
private PlatformOssFilesMapper platformOssFilesMapper;
......@@ -61,15 +65,17 @@ public class AlOssController {
@ApiOperation("阿里云上传")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", dataType = "File", name = "file", value = "文件", required = true),
@ApiImplicitParam(type = "form", dataType = "String", name = "pathName", value = "归类的文件夹名称 比如banner上传就传 banner 返回的地址就会是bnanner/XXX", defaultValue = "other"),
@ApiImplicitParam(type = "form", dataType = "String", name = "pathName", value = "归类的文件夹名称 比如banner上传就传 banner 返回的地址就会是bnanner/XXX", defaultValue = "test"),
@ApiImplicitParam(type = "form", dataType = "Integer", name = "buckType", value = "buckType 1正常的任何文件上传 2apk上传", defaultValue = "1"),
@ApiImplicitParam(type = "form", dataType = "Integer", name = "resize", value = "resize", defaultValue = "0"),
@ApiImplicitParam(type = "form", dataType = "Integer", name = "isCutFrame", value = "是否截取帧数 用于视频获取图片 0不需要 1需要", defaultValue = "0"),
})
public ResponseDto<UploadVo> upload(
@RequestParam MultipartFile file,
@RequestParam(defaultValue = "other") String pathName,
@RequestParam(defaultValue = "1", required = false) int buckType,
@RequestParam(defaultValue = "0", required = false) int resize
@RequestParam(defaultValue = "0", required = false) int resize,
@RequestParam(defaultValue = "0", required = false) int isCutFrame
) {
File fileNew = FilesUtils.multipartFileToFile(file);
if (null == fileNew) {
......@@ -81,7 +87,7 @@ public class AlOssController {
UploadVo uploadVo = new UploadVo();
if (null == ossFile) {
// 上传
ossFile = this.uploadOssFile(file, pathName, buckType, resize, fileNew);
ossFile = this.uploadOssFile(file, pathName, buckType, resize, fileNew, isCutFrame);
}
BeanUtils.copyProperties(ossFile, uploadVo);
......@@ -93,6 +99,7 @@ public class AlOssController {
/**
* 获取老的上传文件
*
* @param file
* @return
*/
......@@ -111,6 +118,7 @@ public class AlOssController {
/**
* 上传文件
*
* @param file
* @param pathName
* @param buckType
......@@ -118,9 +126,25 @@ public class AlOssController {
* @param fileNew
* @return
*/
private PlatformOssFiles uploadOssFile(MultipartFile file, String pathName, int buckType, int resize, File fileNew) {
private PlatformOssFiles uploadOssFile(MultipartFile file, String pathName, int buckType, int resize, File fileNew, int isCutFrame) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
String filename = file.getResource().getFilename();
String filename = "";
String contentType = "";
int size = 0;
if (null == file) {
filename = fileNew.getName();
Path fileNewPath = new File(fileNew.getPath()).toPath();
try {
contentType = Files.probeContentType(fileNewPath);
} catch (Exception e) {
}
size = (int) fileNew.length();
} else {
filename = file.getResource().getFilename();
contentType = file.getContentType();
size = (int) file.getSize();
}
String uploadPath = FilesUtils.getUploadPath(pathName, filename);
String bucketName = FilesUtils.getBucketName(buckType);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, uploadPath, fileNew);
......@@ -130,6 +154,11 @@ public class AlOssController {
this.ossFileResize(resize, uploadPath, bucketName, ossClient);
}
PlatformOssFiles ossFileVideoImg = null;
if (isCutFrame > 0) { // 截取帧数
ossFileVideoImg = this.ossFileCutFrame(uploadPath, pathName, buckType);
}
ossClient.shutdown();
// 入库
......@@ -137,9 +166,12 @@ public class AlOssController {
String ossFilesId = IDGenerator.nextSnowId();
platformOssFilesDate.setOssFilesId(ossFilesId);
platformOssFilesDate.setOssPath(uploadPath);
if (null != ossFileVideoImg) {
platformOssFilesDate.setVideoImg(ossFileVideoImg.getOssPath());
}
platformOssFilesDate.setFileName(filename);
platformOssFilesDate.setContentType(file.getContentType());
platformOssFilesDate.setSize((int) file.getSize());
platformOssFilesDate.setContentType(contentType);
platformOssFilesDate.setSize(size);
String fileMD5 = FilesUtils.getFileMD5(fileNew);
platformOssFilesDate.setMd5str(fileMD5);
platformOssFilesDate.setBuckType(buckType);
......@@ -151,6 +183,7 @@ public class AlOssController {
/**
* oss图片裁切
*
* @param resize
* @param uploadPath
* @param bucketName
......@@ -171,6 +204,12 @@ public class AlOssController {
return processResult;
}
private PlatformOssFiles ossFileCutFrame(String ossFileUrl, String pathName, int buckType) {
String style = "?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,m_fast,ar_auto";
File fileNew = FilesUtils.inputStreamToFile(imgUrl.concat(ossFileUrl).concat(style), System.currentTimeMillis() + ".jpg");
return this.uploadOssFile(null, pathName, buckType, 0, fileNew, 0);
}
@PostMapping("/uploadUrl")
@ApiOperation("阿里云上传URL")
@ApiImplicitParams({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment