{"record":{"id":"c7c4e5235acc69b0","repo":"elunez/eladmin","slug":"error-c7c4e5","errorCode":null,"errorMessage":"文件名不能为空","messagePattern":"文件名不能为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":500,"severity":"warning","filePath":"eladmin-tools/src/main/java/me/zhengjie/service/impl/S3StorageServiceImpl.java","lineNumber":124,"sourceCode":"        }\n    }\n\n    @Override\n    public S3Storage upload(MultipartFile file) {\n        String bucketName = amzS3Config.getDefaultBucket();\n        // 检查存储桶是否存在\n        if (!bucketExists(bucketName)) {\n            log.warn(\"存储桶 {} 不存在，尝试创建...\", bucketName);\n            if (createBucket(bucketName)){\n                log.info(\"存储桶 {} 创建成功。\", bucketName);\n            } else {\n                throw new BadRequestException(\"存储桶创建失败，请检查配置或权限。\");\n            }\n        }\n        // 获取文件名\n        String originalName = file.getOriginalFilename();\n        if (StringUtils.isBlank(originalName)) {\n            throw new IllegalArgumentException(\"文件名不能为空\");\n        }\n        // 生成存储路径和文件名\n        String folder = DateUtil.format(new Date(), amzS3Config.getTimeformat());\n        String fileName = IdUtil.simpleUUID() + \".\" + FileUtil.getExtensionName(originalName);\n        String filePath = folder + \"/\" + fileName;\n        // 构建上传请求\n        PutObjectRequest putObjectRequest = PutObjectRequest.builder()\n                .bucket(amzS3Config.getDefaultBucket())\n                .key(filePath)\n                .build();\n        // 创建 S3Storage 实例\n        S3Storage s3Storage = new S3Storage();\n        try {\n            // 上传文件到 S3\n            s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(file.getInputStream(), file.getSize()));\n            // 设置 S3Storage 属性\n            s3Storage.setFileMimeType(FileUtil.getMimeType(originalName));\n            s3Storage.setFileName(originalName);","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-tools/src/main/java/me/zhengjie/service/impl/S3StorageServiceImpl.java#L106-L142","documentation":"IllegalArgumentException thrown in S3StorageServiceImpl.upload when file.getOriginalFilename() is blank — the multipart part carried no filename (or whitespace). Unlike the BadRequestExceptions around it, this is an IAE, so it escapes as a different exception type and may map to a 500 rather than the usual 400 handler depending on the global handler's coverage.","triggerScenarios":"Uploading a multipart request where the file part has no filename attribute (curl -F 'file=@-' style stream, some programmatic clients), or a filename of empty string / spaces; the later IdUtil.simpleUUID() + '.' + extension logic depends on a parseable filename.","commonSituations":"Custom scripts or API clients (requests/httpx) sending files without an explicit filename; proxy/gateway stripping the filename; frontend FormData appended with an empty filename; some mobile HTTP libraries defaulting to no filename.","solutions":["Ensure the client sends a proper filename: curl -F 'file=@photo.jpg', requests files={'file': ('photo.jpg', fh)}).","On the server, reject earlier at the controller with a 400 @RequestParam validation or a blank-filename check.","If streaming anonymous content is a real use case, generate a synthetic name instead of throwing.","Add IllegalArgumentException to the global exception handler mapping so it returns a clean 400 message."],"exampleFix":"// before\nString originalName = file.getOriginalFilename();\nif (StringUtils.isBlank(originalName)) {\n    throw new IllegalArgumentException(\"文件名不能为空\");\n}\n\n// after: consistent 400 semantics\nString originalName = file.getOriginalFilename();\nif (StringUtils.isBlank(originalName)) {\n    throw new BadRequestException(\"上传文件名不能为空\");\n}","handlingStrategy":"validation","validationCode":"// controller-level guard before the service call\nString name = file.getOriginalFilename();\nif (name == null || name.trim().isEmpty()) {\n    return ResponseEntity.badRequest().body(\"上传必须携带文件名\");\n}","typeGuard":null,"tryCatchPattern":"try { s3StorageService.upload(file); } catch (IllegalArgumentException e) { /* 400-class: fix the client to send filename= in the multipart part */ }","preventionTips":["Always send an explicit filename in multipart parts (curl -F 'file=@x.jpg'; requests files={...} tuple).","Add a blank-filename check at the controller so the error type stays BadRequestException.","Register IllegalArgumentException in the global exception handler to map to a clean 400."],"tags":["s3","file-upload","multipart","validation"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}