| | |
| | | |
| | | @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); |
| | | String upload = ossService.upload(inputStream,file.getOriginalFilename()); |
| | | return R.ok(Cools.add("url", upload)); |
| | | } |
| | | |
| | |
| | | public R sensorUpload(MultipartFile file, @RequestParam("issueId") Long issueId) { |
| | | Issue issue = issueService.selectById(issueId); |
| | | if (null == issue) { |
| | | return R.error("设备不存在"); |
| | | return R.error("故障不存在"); |
| | | } |
| | | String img = issue.getImg(); |
| | | JSONArray jsonArray = JSON.parseArray(img); |
| | |
| | | return R.error("图片上传数量已到上限"); |
| | | } |
| | | // 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); |
| | | String upload = ossService.upload(inputStream,file.getOriginalFilename()); |
| | | if (Cools.isEmpty(upload)) { |
| | | return R.error("上传OSS服务失败"); |
| | | } |
| | | jsonArray.add(upload); |
| | | // 持久化 |
| | | issue.setImg(jsonArray.toJSONString()); |
| | | issue.setUpdateBy(getUserId()); |
| | | issue.setUpdateTime(new Date()); |
| | | if (!issueService.updateById(issue)) { |
| | | return R.error("上传图片失败"); |
| | | } |
| | | return R.ok(Cools.add("src", upload)); |
| | | } |
| | |
| | | issue.setUpdateBy(getUserId()); |
| | | issue.setUpdateTime(new Date()); |
| | | if (!issueService.updateById(issue)) { |
| | | return R.error("保持数据库失败"); |
| | | return R.error("删除图片失败"); |
| | | } |
| | | return R.ok("删除成功"); |
| | | } |