上传换成腾讯的cos
This commit is contained in:
parent
29df08846a
commit
ffa3c54014
|
|
@ -72,7 +72,11 @@
|
|||
<groupId>com.bonus.sgzb</groupId>
|
||||
<artifactId>sgzb-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bonus.sgzb</groupId>
|
||||
<artifactId>sgzb-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.sgzb.file;
|
||||
|
||||
import com.bonus.sgzb.common.security.annotation.EnableRyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
|
|
@ -12,6 +13,7 @@ import com.bonus.sgzb.common.swagger.annotation.EnableCustomSwagger2;
|
|||
*/
|
||||
@EnableCustomSwagger2
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
|
||||
@EnableRyFeignClients
|
||||
public class SgzbFileApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package com.bonus.sgzb.system.config;
|
||||
|
||||
import feign.codec.Encoder;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
|
||||
@Configuration
|
||||
public class FeignClientConfig {
|
||||
|
||||
@Bean
|
||||
public Encoder feignFormEncoder() {
|
||||
return new SpringFormEncoder();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public feign.Logger.Level multipartLoggerLevel() {
|
||||
return feign.Logger.Level.FULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.bonus.sgzb.system.service.feign;
|
||||
|
||||
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@FeignClient(value = "sgzb-file")
|
||||
public interface FileClient {
|
||||
|
||||
@ApiOperation(value = "使用腾讯云文件上传")
|
||||
@PostMapping(value = "/tencent/cos/uploadFile",consumes = "multipart/form-data; boundary=----WebKitFormBoundaryPT06LeXYhc3X1Lna")
|
||||
AjaxResult uploadFile(@RequestPart("file") MultipartFile file);
|
||||
|
||||
}
|
||||
|
|
@ -3,11 +3,13 @@ package com.bonus.sgzb.system.service.impl;
|
|||
import cn.hutool.core.util.IdUtil;
|
||||
import com.bonus.sgzb.common.core.utils.DateTimeHelper;
|
||||
import com.bonus.sgzb.common.core.utils.GlobalConstants;
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
||||
import com.bonus.sgzb.system.api.model.LoginUser;
|
||||
import com.bonus.sgzb.system.domain.FileInfo;
|
||||
import com.bonus.sgzb.system.mapper.FileInfoMapper;
|
||||
import com.bonus.sgzb.system.service.SysFileService;
|
||||
import com.bonus.sgzb.system.service.feign.FileClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hwpf.extractor.WordExtractor;
|
||||
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
||||
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
||||
|
|
@ -20,11 +22,7 @@ import org.springframework.web.multipart.support.StandardMultipartHttpServletReq
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.Security;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +30,7 @@ import java.util.*;
|
|||
*
|
||||
* @author zys
|
||||
*/
|
||||
@Slf4j
|
||||
@Primary
|
||||
@Service("SysFileService")
|
||||
public class SysFileServiceImpl implements SysFileService {
|
||||
|
|
@ -44,6 +43,10 @@ public class SysFileServiceImpl implements SysFileService {
|
|||
@Value("${file.path}")
|
||||
private String localFilePath;
|
||||
|
||||
@Resource
|
||||
private FileClient fileClient;
|
||||
|
||||
|
||||
/**
|
||||
* 本地文件上传接口
|
||||
*
|
||||
|
|
@ -60,7 +63,9 @@ public class SysFileServiceImpl implements SysFileService {
|
|||
List<MultipartFile> items = (List<MultipartFile>) map.get("filePath");
|
||||
MultipartFile item = items.get(0);
|
||||
try {
|
||||
String url = saveFile(request, item, photoType);
|
||||
//String url = saveFile(request, item, photoType);
|
||||
AjaxResult res = fileClient.uploadFile(item);
|
||||
String url = (String) res.get("msg");
|
||||
if (url != null) {
|
||||
int words = getFileText(item);
|
||||
String fileName = item.getOriginalFilename();
|
||||
|
|
@ -93,7 +98,9 @@ public class SysFileServiceImpl implements SysFileService {
|
|||
FileInfo file = new FileInfo();
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
try {
|
||||
String url = saveFilePic(item, fileType);
|
||||
//String url = saveFilePic(item, fileType);
|
||||
AjaxResult res = fileClient.uploadFile(item);
|
||||
String url = (String) res.get("msg");
|
||||
if (url != null) {
|
||||
int words = getFileText(item);
|
||||
String fileName = item.getOriginalFilename();
|
||||
|
|
@ -115,7 +122,6 @@ public class SysFileServiceImpl implements SysFileService {
|
|||
return file;
|
||||
}
|
||||
|
||||
|
||||
public HashMap<String, Object> getFile(StandardMultipartHttpServletRequest request) {
|
||||
MultipartFile multipartFile;
|
||||
HashMap<String, Object> map = new HashMap<String, Object>(16);
|
||||
|
|
|
|||
Loading…
Reference in New Issue