|
@@ -20,6 +20,9 @@ import com.qcloud.cos.auth.COSCredentials;
|
|
import com.qcloud.cos.model.PutObjectRequest;
|
|
import com.qcloud.cos.model.PutObjectRequest;
|
|
import com.qcloud.cos.model.PutObjectResult;
|
|
import com.qcloud.cos.model.PutObjectResult;
|
|
import com.qcloud.cos.region.Region;
|
|
import com.qcloud.cos.region.Region;
|
|
|
|
+import com.qcloud.vod.VodUploadClient;
|
|
|
|
+import com.qcloud.vod.model.VodUploadRequest;
|
|
|
|
+import com.qcloud.vod.model.VodUploadResponse;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiParam;
|
|
import io.swagger.annotations.ApiParam;
|
|
@@ -33,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -50,12 +54,12 @@ public class CommonController
|
|
{
|
|
{
|
|
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
|
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private ServerConfig serverConfig;
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private IFileInfoService fileInfoService;
|
|
private IFileInfoService fileInfoService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private VodUploadClient vodUploadClient;
|
|
|
|
+
|
|
@Value("${cos.bucketName}")
|
|
@Value("${cos.bucketName}")
|
|
private String bucketName;
|
|
private String bucketName;
|
|
@Value("${cos.path}")
|
|
@Value("${cos.path}")
|
|
@@ -76,8 +80,9 @@ public class CommonController
|
|
@ApiOperation("通用上传请求")
|
|
@ApiOperation("通用上传请求")
|
|
public Response<FileInfo> updateload(MultipartFile file,
|
|
public Response<FileInfo> updateload(MultipartFile file,
|
|
@ApiParam(name = "remark", value = "备注,非必传") @RequestParam("remark") String remark,
|
|
@ApiParam(name = "remark", value = "备注,非必传") @RequestParam("remark") String remark,
|
|
- @ApiParam(name = "fileType", value = "业务类型:98-音视频文件、1-商户logo、99-其他")
|
|
|
|
- @RequestParam("fileType") Integer fileType) throws IOException {
|
|
|
|
|
|
+ @ApiParam(name = "fileType", value = "业务类型:1-商户logo、2-汽车品牌logo、3-学车视频、" +
|
|
|
|
+ "98-音视频文件、99-其他")
|
|
|
|
+ @RequestParam("fileType") Integer fileType) throws Exception {
|
|
FileUploadTypeEnum fileUploadTypeEnum = getPathByType(fileType);
|
|
FileUploadTypeEnum fileUploadTypeEnum = getPathByType(fileType);
|
|
String originalFilename = file.getOriginalFilename();
|
|
String originalFilename = file.getOriginalFilename();
|
|
//获取最后一个.的位置
|
|
//获取最后一个.的位置
|
|
@@ -108,16 +113,27 @@ public class CommonController
|
|
}else{
|
|
}else{
|
|
key = "/"+this.preffix+"/"+fileUploadTypeEnum.getFileType()+"/"+storagefileName;
|
|
key = "/"+this.preffix+"/"+fileUploadTypeEnum.getFileType()+"/"+storagefileName;
|
|
}
|
|
}
|
|
-
|
|
|
|
- PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
|
|
|
|
- PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
|
|
|
|
- String fileUrl=this.path + putObjectRequest.getKey();
|
|
|
|
-
|
|
|
|
FileInfo fileInfo = new FileInfo();
|
|
FileInfo fileInfo = new FileInfo();
|
|
- fileInfo.setFileType(fileUploadTypeEnum.getFileType());
|
|
|
|
- fileInfo.setFilePath(key);
|
|
|
|
- fileInfo.setFileUrl(fileUrl);
|
|
|
|
- //fileInfo.setRemark(remark);
|
|
|
|
|
|
+
|
|
|
|
+ //如果是学车视频 ,则调用vod上传
|
|
|
|
+ if (fileUploadTypeEnum.equals(FileUploadTypeEnum.STUDY_MOVIE) ){
|
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
|
+ request.setMediaFilePath(localFile.getAbsolutePath());
|
|
|
|
+ VodUploadResponse response = vodUploadClient.upload("ap-guangzhou", request);
|
|
|
|
+ fileInfo.setFileType(fileUploadTypeEnum.getFileType());
|
|
|
|
+ fileInfo.setFilePath(response.getFileId());
|
|
|
|
+ fileInfo.setFileUrl(response.getMediaUrl());
|
|
|
|
+ }else{
|
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
|
|
|
|
+ cosClient.putObject(putObjectRequest);
|
|
|
|
+ String fileUrl=this.path + putObjectRequest.getKey();
|
|
|
|
+ fileInfo.setFileType(fileUploadTypeEnum.getFileType());
|
|
|
|
+ fileInfo.setFilePath(key);
|
|
|
|
+ fileInfo.setFileUrl(fileUrl);
|
|
|
|
+ }
|
|
|
|
+ if (!StringUtils.isEmpty(remark)){
|
|
|
|
+ fileInfo.setRemark(remark);
|
|
|
|
+ }
|
|
fileInfoService.save(fileInfo);
|
|
fileInfoService.save(fileInfo);
|
|
return Response.success(fileInfo);
|
|
return Response.success(fileInfo);
|
|
}
|
|
}
|