s
luxiaotao1123
2022-02-23 68684d4a664af7891be4b08f594322c32b41d02f
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
46
47
48
49
50
51
52
53
54
55
56
57
package com.zy.sc.common.web;
 
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.sc.common.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.IOException;
import java.io.InputStream;
 
/**
 * Created by vincent on 2020/10/7
 */
@RestController
public class UploadController extends BaseController {
 
    @Autowired
    private OssService ossService;
 
    @PostMapping("/upload.action")
    public R upload(MultipartFile file) {
        String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String upload=ossService.upload(inputStream,suffix);
        return R.ok(Cools.add("url", upload));
    }
 
    @PostMapping("/sensor/upload.action")
    @ManagerAuth(memo = "图片上传")
    public R sensorUpload(MultipartFile file, @RequestParam("sensorId") Long sensorId) {
        // oss
        String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String upload = ossService.upload(inputStream,suffix);
        if (Cools.isEmpty(upload)) {
            return R.error("上传OSS服务失败");
        }
        return R.ok(Cools.add("src", upload));
    }
 
 
}