| | |
| | | import java.io.BufferedInputStream; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | String tempUrl = userDownloadFileDtos.get(0).getTempUrl(); |
| | | String fileName = userDownloadFileDtos.get(0).getFileTypeName() + tempUrl.substring(tempUrl.lastIndexOf("/")); |
| | | |
| | | String originalFileName = userDownloadFileDtos.get(0).getFileTypeName() + tempUrl.substring(tempUrl.lastIndexOf("/")); |
| | | String fileName ; |
| | | try { |
| | | fileName = URLEncoder.encode(originalFileName, StandardCharsets.UTF_8.name()); |
| | | } catch (UnsupportedEncodingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | int lastDotIndex = fileName.lastIndexOf("."); |
| | | if (lastDotIndex != -1) { // 确保存在点 |
| | | fileName = fileName.substring(0, lastDotIndex); |
| | | } |
| | | response.setHeader("content-type", "application/octet-stream"); |
| | | response.setHeader("Content-Disposition", "attachment; filename=" + fileName); |
| | | response.setContentType("application/octet-stream"); |