|
@@ -1,5 +1,6 @@
|
|
|
package com.om.controller.admin;
|
|
|
|
|
|
+import com.om.utils.HuaweiObsUtil;
|
|
|
import com.om.utils.Result;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -30,12 +31,18 @@ public class UtilController {
|
|
|
@Value("${photo.tmp}")
|
|
|
private String tmpPhoto;
|
|
|
|
|
|
+ private final HuaweiObsUtil huaweiObsUtil;
|
|
|
+
|
|
|
+ public UtilController(HuaweiObsUtil huaweiObsUtil) {
|
|
|
+ this.huaweiObsUtil = huaweiObsUtil;
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation("文件下载接口")
|
|
|
@GetMapping("/download")
|
|
|
public void download(String name, HttpServletResponse response) {
|
|
|
try {
|
|
|
//输入流,通过输入流读取文件内容
|
|
|
- FileInputStream fileInputStream = new FileInputStream(fileUploadPath + name);
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(fileUploadPath + name);
|
|
|
//输出流,通过输出流将文件写回浏览器,在浏览器展示图片
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
response.setContentType("image/png");
|
|
@@ -86,7 +93,7 @@ public class UtilController {
|
|
|
public void downloadv(String name, HttpServletResponse response) {
|
|
|
try {
|
|
|
//输入流,通过输入流读取文件内容
|
|
|
- FileInputStream fileInputStream = new FileInputStream(fileUploadPath + name);
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(fileUploadPath + name);
|
|
|
//输出流,通过输出流将文件写回浏览器,在浏览器展示图片
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
response.setContentType("video/mp4");
|
|
@@ -106,29 +113,37 @@ public class UtilController {
|
|
|
@PostMapping("/video")
|
|
|
public Result video(@RequestParam("file") MultipartFile file,
|
|
|
HttpServletRequest request,
|
|
|
- @RequestParam("id") Integer id) {
|
|
|
+ @RequestParam("prefix") String prefix) throws IOException {
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
MultipartFile headerImage = multipartRequest.getFile("file");
|
|
|
- String fileName = headerImage.getOriginalFilename();
|
|
|
-
|
|
|
- //根据当前时间生成文件名
|
|
|
- fileName = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + "." + fileName;
|
|
|
- // 确定文件存放的路径
|
|
|
- File dest = new File(fileUploadPath + fileName);
|
|
|
- //判断当前目录是否存在
|
|
|
- if (!dest.exists()) {
|
|
|
- //目录不存在,需要创建
|
|
|
- dest.mkdir();
|
|
|
- }
|
|
|
- try {
|
|
|
- // 存储文件
|
|
|
- headerImage.transferTo(dest);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("上传文件失败,服务器发生异常!", e);
|
|
|
+ if (headerImage != null) {
|
|
|
+ String fileUrl = huaweiObsUtil.upload(headerImage, prefix);
|
|
|
+ if (fileUrl == null) return Result.fail("上传失败!");
|
|
|
+ else return Result.succ(fileUrl);
|
|
|
+ } else {
|
|
|
+ return Result.fail("文件不正确!");
|
|
|
}
|
|
|
-
|
|
|
- System.out.println("文件名:" + fileName);
|
|
|
-
|
|
|
- return Result.succ(fileName);
|
|
|
+// 以下是上传到本服务器的代码:
|
|
|
+// String fileName = headerImage.getOriginalFilename();
|
|
|
+//
|
|
|
+// //根据当前时间生成文件名
|
|
|
+// fileName = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + "." + fileName;
|
|
|
+// // 确定文件存放的路径
|
|
|
+// File dest = new File(fileUploadPath + fileName);
|
|
|
+// //判断当前目录是否存在
|
|
|
+// if (!dest.exists()) {
|
|
|
+// //目录不存在,需要创建
|
|
|
+// dest.mkdir();
|
|
|
+// }
|
|
|
+// try {
|
|
|
+// // 存储文件
|
|
|
+// headerImage.transferTo(dest);
|
|
|
+// } catch (IOException e) {
|
|
|
+// throw new RuntimeException("上传文件失败,服务器发生异常!", e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// System.out.println("文件名:" + fileName);
|
|
|
+//
|
|
|
+// return Result.succ(fileName);
|
|
|
}
|
|
|
}
|