|
|
@@ -148,4 +148,45 @@ public class FileUploadController {
|
|
|
throw new BusinessException("上传失败", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/video1")
|
|
|
+ public String uploadVideo1(@RequestParam("file") MultipartFile file) {
|
|
|
+ String basePath = "application";
|
|
|
+ try {
|
|
|
+ basePath = file.getContentType().split("/")[0];
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+ String videoPath = basePath + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
+ + RandomStringUtils.randomAlphabetic(8)
|
|
|
+ + "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
+
|
|
|
+ InputStream originInputstream;
|
|
|
+ try {
|
|
|
+ originInputstream = file.getInputStream();
|
|
|
+ if (StringUtils.isEmpty(file.getContentType()) || !file.getContentType().startsWith("video")) {
|
|
|
+ throw new BusinessException(file.getContentType() + " 非视频文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ File destDir = TempFile.createTempDirectory("import." + FilenameUtils.getExtension(file.getOriginalFilename()));
|
|
|
+ file.transferTo(destDir);
|
|
|
+ Long videoTime = VideoUtils.getVideoTime(destDir);
|
|
|
+ log.info("视频长度:" + videoTime);
|
|
|
+
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len;
|
|
|
+ while ((len = originInputstream.read(buffer)) > -1) {
|
|
|
+ baos.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ baos.flush();
|
|
|
+
|
|
|
+ InputStream is1 = new ByteArrayInputStream(baos.toByteArray());
|
|
|
+
|
|
|
+ return storageService.uploadFromInputStream(is1, videoPath);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("上传失败", e);
|
|
|
+ throw new BusinessException("上传失败", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|