疯狂的狮子li
2021-07-20 ed197ce7acddf4183b8459b57f0c39b0284b98b5
ruoyi-oss/src/main/java/com/ruoyi/system/controller/SysOssController.java
@@ -1,6 +1,8 @@
package com.ruoyi.system.controller;
import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
@@ -18,12 +20,15 @@
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -74,6 +79,20 @@
      return AjaxResult.success(map);
   }
   @ApiOperation("下载OSS云存储")
   @PreAuthorize("@ss.hasPermi('system:oss:download')")
   @GetMapping("/download/{ossId}")
   public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
      SysOss sysOss = iSysOssService.getById(ossId);
      if (sysOss == null) {
         throw new CustomException("文件数据不存在!");
      }
      response.reset();
      response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
      long data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false);
      response.setContentLength(Convert.toInt(data));
   }
   /**
    * 删除OSS云存储
    */