Browse Source

根据url 返回文件流

ops-management-platform-backend-dev
gjh 3 weeks ago
parent
commit
349d60fb66
  1. 28
      ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/DocumentInfoController.java
  2. 6
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java
  3. 1
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java
  4. 19
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java

28
ruoyi-modules/guoyan-platform/src/main/java/org/dromara/platform/controller/DocumentInfoController.java

@ -1,26 +1,26 @@
package org.dromara.platform.controller;
import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.platform.domain.vo.DocumentInfoVo;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.platform.domain.bo.DocumentInfoBo;
import org.dromara.platform.domain.vo.DocumentInfoVo;
import org.dromara.platform.service.IDocumentInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 文档信息

6
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysOssController.java

@ -105,4 +105,10 @@ public class SysOssController extends BaseController {
return toAjax(ossService.deleteWithValidByIds(List.of(ossIds), true));
}
@GetMapping("/urlToStream")
public void urlToStream(String url, HttpServletResponse response) throws IOException {
ossService.urlToStream(url,response);
}
}

1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysOssService.java

@ -77,4 +77,5 @@ public interface ISysOssService {
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
void urlToStream(String url, HttpServletResponse response) throws IOException;
}

19
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysOssServiceImpl.java

@ -36,10 +36,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 文件上传 服务层实现
@ -52,6 +49,8 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
private final SysOssMapper baseMapper;
/**
* 查询OSS对象存储列表
*
@ -252,6 +251,18 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
return baseMapper.deleteByIds(ids) > 0;
}
@Override
public void urlToStream(String url, HttpServletResponse response) throws IOException {
LambdaQueryWrapper<SysOss> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysOss::getUrl, url);
SysOss oss = baseMapper.selectOne(queryWrapper);
if (oss == null){
response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");
}else {
download(oss.getOssId(), response);
}
}
/**
* 桶类型为 private 的URL 修改为临时URL时长为120s
*

Loading…
Cancel
Save