{"record":{"id":"451d02217e9a7d9e","repo":"theonedev/onedev","slug":"upload-must-be-less-than","errorCode":null,"errorMessage":"Upload must be less than ","messagePattern":"Upload must be less than ","errorType":"exception","errorClass":"AttachmentTooLargeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/attachment/DefaultAttachmentService.java","lineNumber":605,"sourceCode":"\t\t\t\t\tattachmentName = nameBeforeExt + \"_\" + index + \".\" + ext;\n\t\t\t\t} else {\n\t\t\t\t\tattachmentName = suggestedAttachmentNameCopy + \"_\" + index;\n\t\t\t\t}\n\t\t\t\tindex++;\n\t\t\t}\n\n\t\t\tlong maxUploadFileSize = settingService.getPerformanceSetting().getMaxUploadFileSize() * 1024L * 1024L;\n\n\t\t\tException ex = null;\n\t\t\tFile file = new File(attachmentDir, attachmentName);\n\t\t\ttry (var os = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE)) {\n\t\t\t\tbyte[] buffer = new byte[BUFFER_SIZE];\n\t\t\t\tlong count = 0;\n\t\t\t\tint n;\n\t\t\t\twhile (-1 != (n = attachmentStream.read(buffer))) {\n\t\t\t\t\tcount += n;\n\t\t\t\t\tif (count > maxUploadFileSize) {\n\t\t\t\t\t\tthrow new AttachmentTooLargeException(\"Upload must be less than \"\n\t\t\t\t\t\t\t\t+ FileUtils.byteCountToDisplaySize(maxUploadFileSize));\n\t\t\t\t\t}\n\t\t\t\t\tos.write(buffer, 0, n);\n\t\t\t\t}\n\t\t\t} catch (Exception e) {\n\t\t\t\tex = e;\n\t\t\t}\n\t\t\tif (ex != null) {\n\t\t\t\tif (file.exists())\n\t\t\t\t\tFileUtils.deleteFile(file);\n\t\t\t\tthrow ExceptionUtils.unchecked(ex);\n\t\t\t} else {\n\t\t\t\tif (!attachmentDir.getParentFile().getName().equals(TEMP))\n\t\t\t\t\tprojectService.directoryModified(projectId, attachmentDir);\n\t\t\t\treturn file.getName();\n\t\t\t}\n\t\t});\n\t}","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/attachment/DefaultAttachmentService.java#L587-L623","documentation":"DefaultAttachmentService streams attachment uploads to storage and enforces maxUploadFileSize (the system's attachment size limit). If the streamed byte count exceeds the limit mid-upload, it throws AttachmentTooLargeException('Upload must be less than <human-readable size>').","triggerScenarios":"Uploading any attachment (issue comment file, build artifact attachment) whose size exceeds maxUploadFileSize configured in OneDev system settings.","commonSituations":"Users attaching large log files, dumps, or binaries; administrators lowering the limit without informing users; default limits too small for artifact-heavy workflows.","solutions":["Compress or split the file so it is under the configured limit.","Have an administrator raise max file upload size in Administration -> System Setting.","Upload large artifacts to external storage and attach a link instead."],"exampleFix":"# before\nupload 'build-log-2GB.txt'  # exceeds limit\n# after\ngzip -k build-log-2GB.txt   # or raise limit in Administration -> System Setting\nupload 'build-log-2GB.txt.gz'","handlingStrategy":"validation","validationCode":"const maxBytes = await getMaxUploadFileSize(); // from system setting\nif (file.size >= maxBytes) throw new Error(`File exceeds limit of ${maxBytes} bytes; compress or raise the limit`);","typeGuard":null,"tryCatchPattern":"try { uploadAttachment(file); } catch (e) { if (/Upload must be less than/.test(e.message)) { const smaller = await compressOrSplit(file); return uploadAttachment(smaller); } throw e; }","preventionTips":["Check file size client-side against maxUploadFileSize before uploading","Compress large logs/dumps before attaching","Keep the system setting limit aligned with your team's artifact sizes"],"tags":["attachment","file-size","upload"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}