/ / 块文件上传 public ResponseResult uploadchunk ( MultipartFile file , String fileMd 5 , String chunk ) { if ( file = = null ) { ExceptionCast.cast ( MediaCode.UPLOAD_FILE_REGISTER_ISNULL ) ; } / / 创建块文件目录 boolean fileFold = createChunkFileFolder ( fileMd 5 ) ; / / 块文件 File chunkfile = new File ( getChunkFileFolderPath ( fileMd 5 ) + chunk ) ; / / 上传的块文件 InputStream inputStream = null; FileOutputStream outputStream = null; try { inputStream = file .getInputStream ( ) ; outputStream = new FileOutputStream ( chunkfile ) ; IOUtils. copy ( inputStream , outputStream ) ; } catch ( Exception e ) { e.printStackTrace ( ) ; LOGGER. error ( "upload chunk file fail:{}" , e.getMessage ( ) ) ; ExceptionCast.cast ( MediaCode.CHUNK_FILE_UPLOAD_FAIL ) ; } finally { try { inputStream. close ( ) ; } catch ( IOException e ) { e.printStackTrace ( ) ; } try { outputStream. close ( ) ; } catch ( IOException e ) { e.printStackTrace ( ) ; } } return new ResponseResult ( CommonCode.SUCCESS ) ; } / / 创建块文件目录 private boolean createChunkFileFolder ( String fileMd 5 ) { / / 创建上传文件目录 String chunkFileFolderPath = getChunkFileFolderPath ( fileMd 5 ) ; File chunkFileFolder = new File ( chunkFileFolderPath ) ; if ( !chunkFileFolder. exists ( ) ) { / / 创建文件夹 boolean mkdirs = chunkFileFolder.mkdirs ( ) ; return mkdirs; } return true ; } |