| | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ruoyi.common.config.FileUploadConfig; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.TFile; |
| | |
| | | String token = tokenService.getLoginUser().getToken(); |
| | | StringBuffer url = new StringBuffer(); |
| | | url.append(getLocalUrlPrefix()) |
| | | .append("/cos/get/").append(fileId).append("&s=").append(URLEncoder.encode(token)) |
| | | .append("/cos/get/").append(fileId).append("?s=").append(URLEncoder.encode(token)) |
| | | ; |
| | | return url.toString(); |
| | | } |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | @GetMapping("get/{fileId}") |
| | | public void get(@PathVariable("fileId") String fileid,@RequestParam("s") String s){ |
| | |
| | | failResponse("token不能为空"); |
| | | return; |
| | | } |
| | | Object object = redisCache.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + s); |
| | | if (object==null){ |
| | | failResponse("用户登录已失效"); |
| | | return; |
| | | } |
| | | TFile file = sysFileService.getById(fileid); |
| | | if (file==null){ |
| | | failResponse("图片不存在"); |
| | |
| | | tencentCosUtil.download(file); |
| | | } |
| | | |
| | | |
| | | @GetMapping("get/file") |
| | | public void getFile(@RequestParam("fileUrl") String fileUrl,@RequestParam("s") String s){ |
| | | if (StringUtils.isEmpty(fileUrl)){ |
| | | failResponse("文件路径不能为空"); |
| | | return; |
| | | } |
| | | if (StringUtils.isEmpty(s)){ |
| | | failResponse("token不能为空"); |
| | | return; |
| | | } |
| | | Object object = redisCache.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + s); |
| | | if (object==null){ |
| | | failResponse("用户登录已失效"); |
| | | return; |
| | | } |
| | | tencentCosUtil.download(fileUrl); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * 新上传接口,下一版更新 |
| | | * @param file |
| | | * @param folder 上传到cos的文件目录:如/contract/ |
| | | * @return |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) |
| | | }) |
| | | public R<TFile> upload(@RequestParam("file") MultipartFile file, @RequestParam("folder") String folder) { |
| | | public R<TFile> uploadnew(@RequestParam("file") MultipartFile file, @RequestParam("folder") String folder) { |
| | | TFile tFile = tencentCosUtil.upload(file,folder); |
| | | tFile.setFileUrl(getLocalFileUrlPrefix(tFile.getId())); |
| | | return R.ok(tFile); |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) |
| | | }) |
| | | public R<String> upload(@RequestParam("file") MultipartFile file) { |
| | | String url = tencentCosUtil.upLoadFile(file); |
| | | public R<String> upload(@RequestParam("file") MultipartFile file,@RequestParam("folder") String folder) { |
| | | String url = tencentCosUtil.upLoadFile(file,folder); |
| | | return R.ok(url, url); |
| | | } |
| | | @PostMapping("/downloadImg") |