nnnn
This commit is contained in:
@@ -1,22 +1,26 @@
|
||||
package com.ruoyi.web.controller.cai.app;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.cai.dto.FileResp;
|
||||
import com.ruoyi.cai.dto.app.UploadFileResp;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.util.OfflineTokenManager;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||
import com.ruoyi.system.service.ISysOssService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jdk.nashorn.internal.ir.annotations.Ignore;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@@ -27,6 +31,8 @@ public class FileController {
|
||||
|
||||
@Autowired
|
||||
private ISysOssService iSysOssService;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
|
||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@@ -49,6 +55,43 @@ public class FileController {
|
||||
return R.ok(resp);
|
||||
}
|
||||
|
||||
@GetMapping("/uploadFileSign")
|
||||
public R<UploadFileResp> uploadFileSign() throws Exception {
|
||||
String uploadFileDomain = systemConfigManager.getSystemConfig(SystemConfigEnum.UPLOAD_FILE_DOMAIN);
|
||||
String s = OfflineTokenManager.generateToken(LoginHelper.getUserId() + "");
|
||||
UploadFileResp resp = new UploadFileResp();
|
||||
resp.setDomain(uploadFileDomain);
|
||||
resp.setToken(s);
|
||||
resp.setHttpUrl(uploadFileDomain+"/api/file/uploadImageV2");
|
||||
return R.ok(resp);
|
||||
}
|
||||
|
||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/uploadImageV2", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@Operation(summary = "上传图片类型的文件",
|
||||
parameters = {
|
||||
@Parameter(name = "file", description = "文件", required = true),
|
||||
@Parameter(name = "type", description = "业务类型,dynamic=动态图片,user=用户相册,头像,im=聊天,common=其他", required = false)
|
||||
})
|
||||
@SaIgnore
|
||||
public R<FileResp> uploadImageV1(@RequestPart("file") MultipartFile file,
|
||||
String type, String token) {
|
||||
boolean success = OfflineTokenManager.validateToken(token);
|
||||
if(!success){
|
||||
return R.fail("上传失败,token校验失败");
|
||||
}
|
||||
log.error("上传文件图片类型 type={}",type);
|
||||
if (ObjectUtil.isNull(file)) {
|
||||
return R.fail("上传文件不能为空");
|
||||
}
|
||||
SysOssVo oss = iSysOssService.upload(file);
|
||||
FileResp resp = new FileResp();
|
||||
resp.setUrl(oss.getUrl());
|
||||
resp.setPath(oss.getFileName());
|
||||
resp.setOriginalName(oss.getOriginalName());
|
||||
return R.ok(resp);
|
||||
}
|
||||
|
||||
|
||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||
@PostMapping(value = "/uploadImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
|
||||
Reference in New Issue
Block a user