文件资源服API
- 导入自定义工具jar
file_manager_api-1.0-SNAPSHOT.jar
- pom中添加依赖
<!-- 文件服务器api自定义包引入-->
<dependency>
<groupId>com.yt.cnzz</groupId>
<artifactId>file_manager</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/../library/file_manager_api-1.0-SNAPSHOT.jar</systemPath>
</dependency>
3、启动类添加扫描包 com.yt.file_manager
4、编写业务代码,调用工具方法
package com.mz.party_build.manager_center.test;
import com.alibaba.fastjson.JSONObject;
import com.yt.file_manager.dict.Dict_channel;
import com.yt.file_manager.dto.FileNotRequestData;
import com.yt.file_manager.dto.FileRequestData;
import com.yt.file_manager.dto.FileResponseData;
import com.yt.file_manager.util.RestfulHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
@Controller
@RequestMapping("/TestController")
public class TestController {
private static Logger log = LoggerFactory.getLogger(TestController.class);
private String url="http://127.0.0.1:9313/file_manager/fastdfs/upload/image/sample";
private String channel= Dict_channel.PATY_BUILD;
@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody
public FileResponseData test(MultipartFile file) {
log.info("进入了文件测试服");
FileRequestData fileRequestData=new FileRequestData();
fileRequestData.setChannel(channel);
fileRequestData.setFile(file);
FileResponseData fileResponseData =null;
try {
fileResponseData = RestfulHttpUtil.FileManagerPostFile(url, fileRequestData);
} catch (IOException e) {
e.printStackTrace();
}
log.info("文件测试服结果打印fileResponseData={}", JSONObject.toJSONString(fileResponseData));
//TODO 解析文件服结果,响应
return fileResponseData;
}
@RequestMapping(value = "/testNoFile", method = RequestMethod.POST)
@ResponseBody
public FileResponseData testNoFile(String filePath) {
log.info("进入了文件测试服 filePath={}",filePath);
FileNotRequestData fileNotRequestData=new FileNotRequestData();
fileNotRequestData.setChannel(channel);
FileResponseData fileResponseData =null;
try {
fileResponseData = RestfulHttpUtil.FileManagerPostJson(url, fileNotRequestData);
} catch (IOException e) {
e.printStackTrace();
}
log.info("文件测试服结果打印fileResponseData={}", JSONObject.toJSONString(fileResponseData));
//TODO 解析文件服结果,响应
return fileResponseData;
}
}