| | |
| | | @ApiOperation(value = "新上传照片接口") |
| | | @PostMapping(value = "/uploadimages", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | // try { |
| | | // assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | // String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | // String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | // String imageUrl = minioUtil.upload(file, name); |
| | | // return R.ok(imageUrl); |
| | | // } catch (Exception e) { |
| | | // log.error("上传照片失败【{}】", e.getMessage()); |
| | | // return R.fail(); |
| | | // } |
| | | |
| | | String property = System.getProperty("user.dir"); |
| | | String fileExtension = ".jpg"; |
| | | |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | |
| | | String originName = file.getOriginalFilename(); |
| | | AtomicBoolean isVideo = new AtomicBoolean(false); |
| | | videoExtensionAllow.forEach(ext -> { |
| | | String originNameLowerCase = originName.toLowerCase(); |
| | | if (originNameLowerCase.endsWith("." + ext)) { |
| | | isVideo.set(true); |
| | | } |
| | | }); |
| | | if (isVideo.get()) { |
| | | fileExtension = ".mp4"; |
| | | } |
| | | |
| | | if (originName.toLowerCase().endsWith(".mp3")) { |
| | | fileExtension = ".mp3"; |
| | | } |
| | | |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + fileExtension; |
| | | try { |
| | | assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
| | | String name = UUID.randomUUID().toString().replaceAll("-", "") + "." + extension; |
| | | String imageUrl = minioUtil.upload(file, name); |
| | | return R.ok(imageUrl); |
| | | InputStream is = file.getInputStream(); |
| | | String fileName = |
| | | property + File.separator + UUID.randomUUID().toString().replace("-", "") + fileExtension; |
| | | File file1 = new File(fileName); |
| | | file.transferTo(file1); |
| | | boolean delete = file1.delete(); |
| | | log.info("临时文件删除【{}】", delete); |
| | | sftp.uploadMore(FtpConstants.FTPFILEPATH_IDCARD, name, is); |
| | | sftp.logout(); |
| | | String urls=url + "idcard/" + name; |
| | | return R.ok(urls); |
| | | } catch (Exception e) { |
| | | log.error("上传照片失败【{}】", e.getMessage()); |
| | | log.error("上传文件失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | |
| | | } |
| | | |
| | | // @ApiOperation(value = "批量新增党员导入excel") |