| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Arrays; |
| | | import java.util.Base64; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | /** |
| | |
| | | fileExtension = ".mp4"; |
| | | } |
| | | |
| | | if(originName.toLowerCase().endsWith(".mp3")){ |
| | | fileExtension = ".mp3"; |
| | | } |
| | | |
| | | String fileName = property + File.separator + UUID.randomUUID().toString().replace("-", "") + fileExtension; |
| | | File file1 = new File(fileName); |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "批量上传照片/视频 (jpg/jpeg/png/mp4/mov)") |
| | | @PostMapping(value = "uploads", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R uploadImages(@RequestParam MultipartFile[] files, HttpServletRequest request) throws IOException { |
| | | // 微信图片内容校验 |
| | | // WxMaSecCheckService wxMaSecCheckService = wxMaConfiguration.getMaService().getSecCheckService(); |
| | | String property = System.getProperty("user.dir"); |
| | | String fileExtension = ".jpg"; |
| | | |
| | | List<String> urlList = new ArrayList<>(); |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | |
| | | for (MultipartFile file:files) { |
| | | 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 { |
| | | 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); |
| | | urlList.add(url + "/idcard/" + name); |
| | | } catch (Exception e) { |
| | | log.error("上传文件失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | sftp.logout(); |
| | | return R.ok(urlList); |
| | | } |
| | | } |