{"record":{"id":"1999d6c345b99c3d","repo":"iflytek/astron-agent","slug":"long-content-file-size-out-limit","errorCode":"LONG_CONTENT_FILE_SIZE_OUT_LIMIT","errorMessage":"LONG_CONTENT_FILE_SIZE_OUT_LIMIT","messagePattern":"LONG_CONTENT_FILE_SIZE_OUT_LIMIT","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/chat/impl/ChatEnhanceServiceImpl.java","lineNumber":226,"sourceCode":"     *\n     * @param uid User ID\n     * @param fileName File name\n     * @param fileUrl File URL\n     * @param fileSize File size\n     * @param limitEnum File limit enum, including maximum file size and daily upload count limit\n     * @throws BusinessException Business exception thrown when file name or URL is empty, business type\n     *         is wrong, file size exceeds limit or daily upload count exceeds limit\n     */\n    private void checkFile(String uid, String fileName, String fileUrl, Long fileSize, ChatFileLimitEnum limitEnum) {\n        if (StringUtils.isBlank(fileName) || StringUtils.isBlank(fileUrl)) {\n            throw new BusinessException(ResponseEnum.LONG_CONTENT_MISS_FILE_INFO);\n        }\n        if (limitEnum == null) {\n            throw new BusinessException(ResponseEnum.LONG_CONTENT_WRONG_BUSINESS_TYPE);\n        }\n        // Current document size validation\n        if (fileSize > limitEnum.getMaxSize()) {\n            throw new BusinessException(ResponseEnum.LONG_CONTENT_FILE_SIZE_OUT_LIMIT);\n        }\n        // Daily maximum upload count limit\n        if (redissonClient.getAtomicLong(limitEnum.getRedisPrefix() + uid).addAndGet(1L) > limitEnum.getDailyUploadNum()) {\n            redissonClient.getAtomicLong(limitEnum.getRedisPrefix() + uid).addAndGet(-1L);\n            throw new BusinessException(ResponseEnum.LONG_CONTENT_FILE_NUM_OUT_LIMIT);\n        }\n    }\n\n    /**\n     * Handle document upload functionality\n     *\n     * @param chatFileUserId Chat file user ID\n     * @param uid User ID\n     * @param chatId Chat ID\n     * @param fileUrl File URL\n     * @param fileName File name\n     * @param fileSize File size\n     * @param limitEnum File limit enum","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/chat/impl/ChatEnhanceServiceImpl.java#L208-L244","documentation":"checkFile compares the uploaded file's size against limitEnum.getMaxSize() for the given business type. When fileSize exceeds that configured maximum, it throws LONG_CONTENT_FILE_SIZE_OUT_LIMIT, telling the user the document is too large for this chat long-content upload.","triggerScenarios":"Calling saveFile with a fileSize (in bytes) larger than the maxSize configured on the resolved ChatFileLimitEnum, e.g. uploading a 50MB PDF when the enum caps documents at 20MB.","commonSituations":"Users uploading large PDFs/Word docs through the chat document-upload feature; a frontend that computed size incorrectly (e.g. KB vs bytes); a limit enum that was tightened without updating client-side pre-checks; multipart encoding overhead pushing a borderline file over the limit.","solutions":["Compress or split the document so it is under the configured maxSize before uploading.","Check ChatFileLimitEnum.getMaxSize() for the business type and inform the user of the exact allowed size.","If the business requirement legitimately needs larger files, raise maxSize in the enum (considering nginx/gateway body limits too).","Add a client-side size check that rejects oversize files before the upload request is made."],"exampleFix":"// before\nuploadFile(file); // server throws when file.length() > limit\n// after\nlong maxBytes = ChatFileLimitEnum.DOCUMENT.getMaxSize();\nif (file.length() > maxBytes) {\n    throw new IllegalArgumentException(\"File exceeds max size \" + maxBytes + \" bytes\");\n}\nuploadFile(file);","handlingStrategy":"validation","validationCode":"long maxSize = ChatFileLimitEnum.DOCUMENT.getMaxSize();\nif (file != null && file.getSize() > maxSize) {\n    throw new IllegalArgumentException(\"File exceeds \" + maxSize + \" bytes\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    chatEnhanceService.saveFile(uid, fileName, fileUrl, fileSize, businessType);\n} catch (BusinessException e) {\n    if (ResponseEnum.LONG_CONTENT_FILE_SIZE_OUT_LIMIT.equals(e.getResponseEnum())) {\n        // inform user of max allowed size and offer compression\n    }\n}","preventionTips":["Pre-check file.size() against the published limit in the frontend before uploading.","Expose maxSize per business type via a config API so clients stay in sync.","Account for encoding overhead (base64/multipart) when computing size client-side."],"tags":["file-size","validation","java","file-upload"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}