阿里视频上传

阿里视频上传

 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;

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值