FileControl.java
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.example.dahua.control;
import com.example.dahua.bean.UploadImg;
import com.example.dahua.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@RestController
@Api("文件管理器")
@RequestMapping("file/*")
public class FileControl {
@Autowired
UserService userService;
@RequestMapping(method = RequestMethod.POST, value = "uploadImg")
public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode,
@RequestParam("clint_type") String clint_type,@RequestParam("userType") int userType) {
System.out.println("schoolId:" + schoolId + " studentCode:" + studentCode);
String fileName = file.getOriginalFilename();//文件名
File outFile = new File("C://imgCom");
if (!outFile.exists()) outFile.mkdirs();
try {
File dest = new File(outFile, fileName);
FileOutputStream fileOutputStream = new FileOutputStream(dest);
fileOutputStream.write(file.getBytes());
userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type,userType);
return "1";
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "0";
}
}