|
@@ -3,6 +3,7 @@ package com.huimv.farm.damsubsidy.common.utils;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
import com.jcraft.jsch.*;
|
|
|
+import lombok.Data;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
@@ -20,17 +21,28 @@ import java.util.List;
|
|
|
@Component
|
|
|
public class UploadImage {
|
|
|
|
|
|
- private static String basePath = "/home/huimv/img/";
|
|
|
+ @Value("${img.basePath}")
|
|
|
+ private String basePath;
|
|
|
|
|
|
-// private static String ip = "139.9.167.178";
|
|
|
-// private static String ip = "36.134.209.211";
|
|
|
- private static String ip = "192.168.0.13";
|
|
|
+ @Value("${img.ip}")
|
|
|
+ private String ip ;
|
|
|
+// private String ip = "36.134.209.211";
|
|
|
+// private String ip = "192.168.0.13";
|
|
|
|
|
|
- private static String user = "huimv";
|
|
|
+ @Value("${img.user}")
|
|
|
+ private String user ;
|
|
|
|
|
|
- private static String password = "!Hm537e@1";
|
|
|
+// private String password = "!Hm537e@1";
|
|
|
+
|
|
|
+ @Value("${img.password}")
|
|
|
+ private String password ;
|
|
|
+
|
|
|
+ @Value("${img.port}")
|
|
|
+ public Integer port ;
|
|
|
+
|
|
|
+ @Value("${img.url}")
|
|
|
+ public String url ;
|
|
|
|
|
|
- public static Integer port = 22;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -39,7 +51,7 @@ public class UploadImage {
|
|
|
* @param fileName 文件名
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public static void sshSftp(byte[] bytes,String path,String fileName) throws Exception{
|
|
|
+ public void sshSftp(byte[] bytes,String path,String fileName) throws Exception{
|
|
|
|
|
|
// 服务器保存路径
|
|
|
String filepath = basePath +path ;
|
|
@@ -114,7 +126,7 @@ public class UploadImage {
|
|
|
}
|
|
|
|
|
|
//上传压缩的图片
|
|
|
- public static String getImageCom(MultipartFile image) throws IOException {
|
|
|
+ public String getImageCom(MultipartFile image) throws IOException {
|
|
|
//获取文件输入流
|
|
|
InputStream inputStream = image.getInputStream();
|
|
|
String originalFilename = image.getOriginalFilename();
|
|
@@ -134,7 +146,7 @@ public class UploadImage {
|
|
|
byte[] bytes = bos.toByteArray();
|
|
|
String imgname = UUID.randomUUID() + "." + filenameExtension;
|
|
|
sshSftp(bytes, path, imgname);
|
|
|
- return "https://dam.img.ifarmcloud.com:8030/images/" + path + "/" + imgname;
|
|
|
+ return url+ path + "/" + imgname;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return "上传失败";
|
|
@@ -163,7 +175,7 @@ public class UploadImage {
|
|
|
byte[] content = out.toByteArray();
|
|
|
String imgname = UUID.randomUUID() + "." + filenameExtension;
|
|
|
sshSftp(content, path, imgname);
|
|
|
- return "https://dam.img.ifarmcloud.com:8030/images/" + path + "/" + imgname;
|
|
|
+ return url + path + "/" + imgname;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return "上传失败";
|