Search in sources :

Example 1 with SysOss

use of com.ruoyi.system.domain.SysOss in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysProfileController method avatar.

/**
 * 头像上传
 */
@ApiOperation("头像上传")
@ApiImplicitParams({ @ApiImplicitParam(name = "avatarfile", value = "用户头像", paramType = "query", dataTypeClass = File.class, required = true) })
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
@PostMapping("/avatar")
public R<Map<String, Object>> avatar(@RequestPart("avatarfile") MultipartFile file) {
    Map<String, Object> ajax = new HashMap<>();
    if (!file.isEmpty()) {
        SysOss oss = iSysOssService.upload(file);
        String avatar = oss.getUrl();
        if (userService.updateUserAvatar(getUsername(), avatar)) {
            ajax.put("imgUrl", avatar);
            return R.ok(ajax);
        }
    }
    return R.fail("上传图片异常,请联系管理员");
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) HashMap(java.util.HashMap) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) Log(com.ruoyi.common.annotation.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with SysOss

use of com.ruoyi.system.domain.SysOss in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysOssServiceImpl method deleteWithValidByIds.

@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
    if (isValid) {
    // 做一些业务上的校验,判断是否需要校验
    }
    List<SysOss> list = baseMapper.selectBatchIds(ids);
    for (SysOss sysOss : list) {
        IOssStrategy storage = OssFactory.instance(sysOss.getService());
        storage.delete(sysOss.getUrl());
    }
    return baseMapper.deleteBatchIds(ids) > 0;
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) IOssStrategy(com.ruoyi.oss.service.IOssStrategy)

Example 3 with SysOss

use of com.ruoyi.system.domain.SysOss in project RuoYi-Vue-Plus by JavaLionLi.

the class SysOssController method upload.

/**
 * 上传OSS对象存储
 */
@ApiOperation("上传OSS对象存储")
@ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "文件", paramType = "query", dataTypeClass = File.class, required = true) })
@SaCheckPermission("system:oss:upload")
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
@PostMapping("/upload")
public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
    if (ObjectUtil.isNull(file)) {
        throw new ServiceException("上传文件不能为空");
    }
    SysOss oss = iSysOssService.upload(file);
    Map<String, String> map = new HashMap<>(2);
    map.put("url", oss.getUrl());
    map.put("fileName", oss.getFileName());
    return R.ok(map);
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) HashMap(java.util.HashMap) Log(com.ruoyi.common.annotation.Log) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 4 with SysOss

use of com.ruoyi.system.domain.SysOss in project RuoYi-Vue-Plus by JavaLionLi.

the class SysOssController method download.

@ApiOperation("下载OSS对象存储")
@SaCheckPermission("system:oss:download")
@GetMapping("/download/{ossId}")
public void download(@ApiParam("OSS对象ID") @PathVariable Long ossId, HttpServletResponse response) throws IOException {
    SysOss sysOss = iSysOssService.getById(ossId);
    if (ObjectUtil.isNull(sysOss)) {
        throw new ServiceException("文件数据不存在!");
    }
    response.reset();
    FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
    response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
    long data;
    try {
        data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false);
    } catch (HttpException e) {
        if (e.getMessage().contains("403")) {
            throw new ServiceException("无读取权限, 请在对应的OSS开启'公有读'权限!");
        } else {
            throw new ServiceException(e.getMessage());
        }
    }
    response.setContentLength(Convert.toInt(data));
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) HttpException(cn.hutool.http.HttpException) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 5 with SysOss

use of com.ruoyi.system.domain.SysOss in project RuoYi-Vue-Plus by JavaLionLi.

the class SysProfileController method avatar.

/**
 * 头像上传
 */
@ApiOperation("头像上传")
@ApiImplicitParams({ @ApiImplicitParam(name = "avatarfile", value = "用户头像", paramType = "query", dataTypeClass = File.class, required = true) })
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
@PostMapping("/avatar")
public R<Map<String, Object>> avatar(@RequestPart("avatarfile") MultipartFile file) {
    Map<String, Object> ajax = new HashMap<>();
    if (!file.isEmpty()) {
        SysOss oss = iSysOssService.upload(file);
        String avatar = oss.getUrl();
        if (userService.updateUserAvatar(getUsername(), avatar)) {
            ajax.put("imgUrl", avatar);
            return R.ok(ajax);
        }
    }
    return R.fail("上传图片异常,请联系管理员");
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) HashMap(java.util.HashMap) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) Log(com.ruoyi.common.annotation.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SysOss (com.ruoyi.system.domain.SysOss)10 ServiceException (com.ruoyi.common.exception.ServiceException)6 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)4 Log (com.ruoyi.common.annotation.Log)4 IOssStrategy (com.ruoyi.oss.service.IOssStrategy)4 HashMap (java.util.HashMap)4 HttpException (cn.hutool.http.HttpException)2 UploadResult (com.ruoyi.oss.entity.UploadResult)2 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)2 ApiOperation (io.swagger.annotations.ApiOperation)2 IOException (java.io.IOException)2