2026-04-28 a7dd93b840bdce4bd0011bc948157f440514a207
src/main/java/com/ruoyi/project/common/CommonController.java
@@ -128,15 +128,32 @@
//    }
    @PostMapping({"/upload"})
    @Operation(summary = "文件上传")
    public R upload(@RequestParam("files") List<MultipartFile> files) throws Exception {
        return R.ok(storageBlobService.upload(files));
    public R upload(@RequestParam("files") List<MultipartFile> files) {
        return R.ok(storageBlobService.upload(files, false));
    }
    /**
     * 公共文件上传
     * 此接口上传的文件永久有效,慎用
     */
    @PostMapping({"/public/upload"})
    @Operation(summary = "文件上传")
    public R publicUpload(@RequestParam("files") List<MultipartFile> files) {
        return R.ok(storageBlobService.upload(files, true));
    }
    @GetMapping("/download/{fileName}")
    @Anonymous
    public void download(@PathVariable String fileName, @RequestParam("token") String token, HttpServletResponse response) throws Exception {
        File file = storageBlobService.getFileByToken(fileName, token);
    public void download(@PathVariable String fileName,
                         @RequestParam(value = "token", required = false) String token,
                         @RequestParam(value = "publicKey", required = false) String publicKey,
                         HttpServletResponse response) throws Exception {
        File file;
        if (publicKey != null) {
            file = fileUtil.compressFile(storageBlobService.getPublicFile(fileName, publicKey));
        } else {
            file = fileUtil.compressFile(storageBlobService.getFileByToken(fileName, token));
        }
        String originalFileName = storageBlobService.getDownloadFileName(fileName);
        String encodedFileName = URLEncoder.encode(originalFileName, StandardCharsets.UTF_8.name()).replace("+", "%20");
        response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + encodedFileName);
@@ -147,8 +164,14 @@
    @GetMapping("/preview/{fileName}")
    @Anonymous
    public ResponseEntity<FileSystemResource> preview(@PathVariable String fileName,
                                                      @RequestParam("token") String token) throws Exception {
        File file = fileUtil.compressFile(storageBlobService.getFileByToken(fileName, token));
                                                      @RequestParam(value = "token", required = false) String token,
                                                      @RequestParam(value = "publicKey", required = false) String publicKey) throws Exception {
        File file;
        if (publicKey != null) {
            file = fileUtil.compressFile(storageBlobService.getPublicFile(fileName, publicKey));
        } else {
            file = fileUtil.compressFile(storageBlobService.getFileByToken(fileName, token));
        }
        String contentType = Files.probeContentType(file.toPath());
        ContentDisposition contentDisposition = ContentDisposition.inline()