diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java b/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java index 082595e96..597d9d55e 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/video/VideoController.java @@ -17,6 +17,7 @@ import com.iformall.domain.po.WxMerchant; import com.iformall.domain.po.WxPropertyContract; import com.iformall.domain.po.WxRentContract; import com.iformall.domain.po.WxShop; +import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.po.base.BaseEntity.SortField; import com.iformall.enums.EnumContractOperationType; import com.iformall.enums.EnumContractType; @@ -40,12 +41,14 @@ import com.iformall.video.entity.VideUploadResult; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -70,12 +73,33 @@ public class VideoController extends BaseController { @Autowired String videoType; - @GetMapping("/upload") + @GetMapping("/test") @ApiImplicitParams({ @ApiImplicitParam(name = "title", value = "页数", dataType = "String", paramType = "query", required = true)}) public ResultData list(@ModelAttribute WxPropertyContract wxPropertyContract, String title) { VideUploadResult result = videoFactory.getExcutor(videoType).uploadLocalVideo("123123213", "/root/111.mp4"); return new ResultData(result); } + + /** + * 上传视频 + * + * @param multiReq + * @return + * @throws Exception + */ + @PostMapping(value = "/upload", consumes = "multipart/*", headers = "content-type=multipart/form-data") + @ApiOperation("上传视频") + @SystemControllerLog(description = "文件上传") + public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq,@RequestParam Map param) { + try { + String title = param.get("title"); + VideUploadResult result = videoFactory.getExcutor(videoType).uploadLocalVideo(title, multiReq.getInputStream()); + return new ResultData(result); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); + } + } } diff --git a/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java b/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java index 413db34b1..3fa6395cb 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java +++ b/mallinkVideo/src/main/java/com/iformall/video/VideoExcutor.java @@ -1,6 +1,7 @@ package com.iformall.video; import java.io.File; +import java.io.InputStream; import com.iformall.video.entity.VideUploadResult; @@ -12,7 +13,7 @@ public interface VideoExcutor { */ public VideUploadResult uploadLocalVideo(String title,String localFile); - public VideUploadResult uploadLocalVideo(String title,File localFile); + public VideUploadResult uploadLocalVideo(String title,InputStream inputStream); //ext,后缀名 public VideUploadResult uploadNetVideo(String title,String url,String ext); diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java index 538e0f8a0..d95fe4f24 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/AliyunVideoExcutor.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -59,13 +60,11 @@ public class AliyunVideoExcutor implements VideoExcutor { } @Override - public VideUploadResult uploadLocalVideo(String title,File localFile) { + public VideUploadResult uploadLocalVideo(String title,InputStream inputStream) { VideUploadResult result = new VideUploadResult(); UploadStreamResponse response; - FileInputStream inputStream = null; try { - inputStream = new FileInputStream(localFile); - response = AliyunVedioUpload.uploadStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, localFile.getName(), inputStream); + response = AliyunVedioUpload.uploadStream(config.getAccessKeyId(), config.getAccessKeySecret(),config.getRegionId(), title, "", inputStream); if (response.isSuccess()) { result.setVideoId(response.getVideoId()); result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); @@ -74,7 +73,7 @@ public class AliyunVideoExcutor implements VideoExcutor { result.setSuccess(false); result.setMsg("ErrorCode["+response.getCode()+"]"+response.getMessage()); } - } catch (FileNotFoundException e) { + } catch (Exception e) { log.error("aliyun uploadLocalVideo error",e); result.setSuccess(false); result.setMsg(e.getLocalizedMessage()); diff --git a/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java index 95ed16498..2bc7844bc 100644 --- a/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java +++ b/mallinkVideo/src/main/java/com/iformall/video/aliyun/sdk/upload/AliyunVedioUpload.java @@ -229,7 +229,7 @@ public class AliyunVedioUpload { /* 网络文件下载读取超时,单位毫秒,0-表示不限制*/ request.setDownloadReadTimeout(0); /* 网络文件下载后保存的本地目录*/ - request.setLocalDownloadFilePath("/Users/download"); + request.setLocalDownloadFilePath("/aliyunvideo/download"); /* 是否显示水印(可选),指定模板组ID时,根据模板组配置确定是否显示水印*/ //request.setShowWaterMark(true); /* 自定义消息回调设置(可选),参数说明参考文档 https://help.aliyun.com/document_detail/86952.html#UserData */