| | |
| | | import io.minio.messages.DeleteError; |
| | | import io.minio.messages.DeleteObject; |
| | | import io.minio.messages.Item; |
| | | import jakarta.servlet.ServletOutputStream; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import org.apache.commons.compress.utils.IOUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpHeaders; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查看文件对象 |
| | | * @param bucketName 存储bucket名称 |
| | | * @return 存储bucket内文件对象信息 |
| | | * 下载文件 |
| | | * |
| | | * @param originalName 文件路径 |
| | | */ |
| | | public InputStream downloadFile(String originalName, HttpServletResponse response) { |
| | | try { |
| | | |
| | | InputStream file = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(originalName).build()); |
| | | String filename = new String(originalName.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); |
| | | if (StringUtils.isNotBlank(originalName)) { |
| | | filename = originalName; |
| | | } |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + filename); |
| | | ServletOutputStream servletOutputStream = response.getOutputStream(); |
| | | int len; |
| | | byte[] buffer = new byte[1024]; |
| | | while ((len = file.read(buffer)) > 0) { |
| | | servletOutputStream.write(buffer, 0, len); |
| | | } |
| | | servletOutputStream.flush(); |
| | | file.close(); |
| | | servletOutputStream.close(); |
| | | return file; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |