阿里视频上传
public ResponseBean uploadVideo(MultipartFile file, HttpServletRequest request) {
ResponseBean responseBean = new ResponseBean();
responseBean.setSuccess(false);
Integer userId = JwtTokenUtil.getUserId(request);
if (userId == null && "0".equals(userId)) {
responseBean.setMessage("未获取到当前用户信息");
return responseBean;
}
if (ToolUtil.isEmpty(file)) {
responseBean.setMessage("附件不能为空");
return responseBean;
}
String uuid = UUIDGenerator.getUUID();
uuid = uuid.substring(0, 4);
String str = file.getOriginalFilename();
String str01 = str.substring(str.lastIndexOf("."), str.length());
StringBuilder builder = new StringBuilder();
String uuid1 = UUIDGenerator.getUUID();
builder.append(uuid1);
builder.append(str01);
String objName = ImageObjNameUtil.generateObjName(userId + "", uuid, ImageObjNameUtil.ImageType.VIDEO, builder.toString());
// 图片上传
String image = objName.substring(objName.lastIndexOf(".") + 1);
if (image.equals("jpeg")) {
objName = objName.replace(objName.substring(objName.lastIndexOf(".") + 1), "jpg");
}
boolean success = false;
try {
success = OSSUtil.uploadVideo(file, objName);
} catch (IOException e) {
e.printStackTrace();
}
if (!success) {
responseBean.setCode(500);
responseBean.setMessage("上传失败请重试");
return responseBean;
}
responseBean.setSuccess(true);
responseBean.setCode(200);
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("url", objName);
stringStringHashMap.put("name", str);
responseBean.setData(stringStringHashMap);
return responseBean;
}