|
@@ -0,0 +1,76 @@
|
|
|
|
+package com.huimv.farm.damsubsidy.controller;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
|
+import cn.hutool.core.util.CharsetUtil;
|
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
|
+import cn.hutool.crypto.digest.MD5;
|
|
|
|
+import cn.hutool.crypto.symmetric.AES;
|
|
|
|
+import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
|
|
|
|
+import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
|
|
|
+import com.huimv.farm.damsubsidy.common.utils.UploadImage;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.util.Date;
|
|
|
|
+
|
|
|
|
+@CrossOrigin
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/image")
|
|
|
|
+public class ImagesTest {
|
|
|
|
+
|
|
|
|
+ @Value("${img.port}")
|
|
|
|
+ public static Integer port;
|
|
|
|
+ @PostMapping("/test")
|
|
|
|
+ public String test( @RequestParam("image") MultipartFile image ){
|
|
|
|
+ String imgname = "成功";
|
|
|
|
+ String originalFilename = image.getOriginalFilename();
|
|
|
|
+ String filenameExtension = StringUtils.getFilenameExtension(originalFilename);
|
|
|
|
+ String path = DateUtil.format(new Date(),"yyyy-MM");
|
|
|
|
+ try {
|
|
|
|
+ InputStream inputStream = image.getInputStream();
|
|
|
|
+ BufferedInputStream in = new BufferedInputStream(inputStream);
|
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
|
|
|
+
|
|
|
|
+ byte[] temp = new byte[1024];
|
|
|
|
+ int size = 0;
|
|
|
|
+ while ((size = in.read(temp)) != -1) {
|
|
|
|
+ out.write(temp, 0, size);
|
|
|
|
+ }
|
|
|
|
+ in.close();
|
|
|
|
+ byte[] content = out.toByteArray();
|
|
|
|
+ imgname =UUID.randomUUID()+"."+filenameExtension;
|
|
|
|
+ UploadImage.sshSftp(content,path, imgname);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ String content = "http://139.9.167.178/images"+path +"/"+imgname;
|
|
|
|
+
|
|
|
|
+ return content;
|
|
|
|
+// byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
|
|
|
|
+// System.out.println(key);
|
|
|
|
+
|
|
|
|
+//构建
|
|
|
|
+// SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
|
|
|
|
+//加密为16进制表示
|
|
|
|
+ // aes.encryptHex(content);
|
|
|
|
+ // System.out.println(encryptHex);
|
|
|
|
+////解密为字符串
|
|
|
|
+// String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
|
|
|
+// System.out.println(decryptStr);
|
|
|
|
+// return aes.encryptHex(content);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// public static void main(String[] args) {
|
|
|
|
+//
|
|
|
|
+// String content = "http://139.9.167.178/images";
|
|
|
|
+// MD5 md5 = MD5.create();
|
|
|
|
+// String s = md5.digestHex16(content);
|
|
|
|
+// System.out.println(s);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|