diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java index 47e90321..5778b2a0 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java @@ -3,6 +3,7 @@ package com.ruoyi.web.controller.system; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.http.HttpException; import cn.hutool.http.HttpUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.common.annotation.Log; @@ -103,7 +104,16 @@ public class SysOssController extends BaseController { response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); FileUtils.setAttachmentResponseHeader(response, URLEncoder.encode(sysOss.getOriginalName(), StandardCharsets.UTF_8.toString())); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8"); - long data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false); + 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)); }