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));
|
}
|
|
|
}
|