java miniopdf getObject_11">一、java 通过minio下载pdf 附件getObject方法
java"> @Resource private MinioClient minioClient; public void getObject ( String fileName, String originalName, HttpServletResponse response) throws IOException { InputStream inputStream = null ; OutputStream outputStream = null ; try { String filePath = "/" ; GetObjectArgs build = GetObjectArgs . builder ( ) . bucket ( "桶名" ) . object ( filePath + fileName) . build ( ) ; inputStream = minioClient. getObject ( build) ; response. setContentType ( "application/pdf ;charset=utf-8" ) ; response. setCharacterEncoding ( "utf-8" ) ; String encodedFileName = URLEncoder . encode ( originalName, "UTF-8" ) . replace ( "+" , "%20" ) ; response. setHeader ( "Content-disposition" , "attachment;filename=\"" + encodedFileName + "\"" ) ; outputStream = response. getOutputStream ( ) ; byte [ ] buffer = new byte [ 4096 ] ; int bytesRead; while ( ( bytesRead = inputStream. read ( buffer) ) != - 1 ) { outputStream. write ( buffer, 0 , bytesRead) ; } } catch ( Exception e) { e. printStackTrace ( ) ; throw new BizException ( "附件下载失败,请重试" ) ; } finally { inputStream. close ( ) ; outputStream. close ( ) ; } }