
- 在项目resource中添加tracker.conf 配置文件
- 创建FileUploadController控制器
tracker_server=192.168.200.128:22122 # 连接超时时间,针对socket套接字函数connect,默认为30秒 connect_timeout=30000 # 网络通讯超时时间,默认是60秒 network_timeout=60000创建FileUploadController控制器
@RestController
@RequestMapping("admin/product/")
public class FileUploadController {
@Value("${fileServer.url}")
private String fileUrl;
@RequestMapping("fileUpload")
public Result fileUpload(MultipartFile file) throws Exception{
String configFile = this.getClass().getResource("/tracker.conf").getFile();
String path = null;
if (configFile!=null){
// 初始化
ClientGlobal.init(configFile);
// 创建trackerClient
TrackerClient trackerClient = new TrackerClient();
// 获取trackerService
TrackerServer trackerServer = trackerClient.getConnection();
// 创建storageClient1
StorageClient1 storageClient1 = new StorageClient1(trackerServer, null);
path = storageClient1.upload_appender_file1(file.getBytes(), FilenameUtils.getExtension(file.getOriginalFilename()), null);
System.out.println(fileUrl + path);
}
return Result.ok(fileUrl+path);
}
}
利用@Value 标签可以引用application.yml中的值
fileServer: url: http://192.168.200.128:8080/
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)