|
@@ -0,0 +1,64 @@
|
|
|
+package com.caimei.utils;
|
|
|
+
|
|
|
+import com.caimei.modules.fastDFS.FastDFSClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Controller
|
|
|
+@RequestMapping("formData")
|
|
|
+public class formDataUtils {
|
|
|
+ @Autowired
|
|
|
+ private FastDFSClient client;
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/MultiPictareaddData")
|
|
|
+ public Map<String, Object> MultiPictareaddData(MultipartFile[] file, HttpServletRequest request) throws IOException {
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ String saveFile = null;
|
|
|
+ if (file != null && file.length > 0) {
|
|
|
+ System.out.println(file.length);
|
|
|
+ for (int i = 0; i < file.length; i++) {
|
|
|
+ MultipartFile filex = file[i];
|
|
|
+ // 保存文件
|
|
|
+ saveFile = saveFile(request, filex);
|
|
|
+ }
|
|
|
+ map.put("success", saveFile);
|
|
|
+ map.put("msg", "上传成功");
|
|
|
+ } else {
|
|
|
+ System.out.println(file.length + ":长度就是零");
|
|
|
+ map.put("msg", "上传失败");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String saveFile(HttpServletRequest request, MultipartFile file) throws IOException {
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ String name = file.getName();
|
|
|
+ String randomUUID = UUID.randomUUID().toString();
|
|
|
+ int index = originalFilename.lastIndexOf(".");
|
|
|
+ String exet = originalFilename.substring(index);
|
|
|
+ String file1 = client.uploadFile(randomUUID + exet);
|
|
|
+ return file1;
|
|
|
+
|
|
|
+ /*Date date = new Date();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd\\HH\\mm\\ss");
|
|
|
+ String dateStr = sdf.format(date); // D:\\uploads\\20180824 String
|
|
|
+ String filePath = "D:\\uploads\\" + dateStr;
|
|
|
+ System.out.println("filePath=" + filePath);
|
|
|
+ File file2 = new File(filePath);
|
|
|
+ if (!file2.exists()) {
|
|
|
+ file2.mkdirs();
|
|
|
+ }
|
|
|
+ filePath += "\\" + randomUUID + exet;
|
|
|
+ System.out.println(filePath + "P");
|
|
|
+ file.transferTo(new File(filePath));// ctrl+1*/
|
|
|
+ }
|
|
|
+}
|