chengf
2025-09-15 ebf6117ccea680eae81a91f2fa355ce3a76eb621
service-api/src/main/java/com/java110/api/controller/app/file/UserDownloadFileController.java
@@ -19,6 +19,9 @@
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;
/**
@@ -58,8 +61,17 @@
        }
        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");