{"record":{"id":"0f24add509f796f4","repo":"alibaba/spring-ai-alibaba","slug":"read-dsl-file-failed-please-check-if-the-encoding","errorCode":null,"errorMessage":"Read dsl file failed, please check if the encoding of file is UTF_8 ","messagePattern":"Read dsl file failed, please check if the encoding of file is UTF_8 ","errorType":"exception","errorClass":"SerializationException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/api/DSLAPI.java","lineNumber":99,"sourceCode":"\t@Operation(summary = \"import app from dsl\", tags = { \"DSL\" })\n\t@PostMapping(value = \"/import\", produces = \"application/json\")\n\tdefault R<App> importDSL(@RequestBody DSLParam param) {\n\t\tDSLDialectType dialectType = DSLDialectType.fromValue(param.getDialect())\n\t\t\t.orElseThrow(() -> new NotImplementedException(\"Unsupported dsl dialect: \" + param.getDialect()));\n\t\tApp app = getAdapter(dialectType).importDSL(param.getContent());\n\t\tapp = getAppSaver().save(app);\n\t\treturn R.success(app);\n\t}\n\n\t@Operation(summary = \"import app from dsl file \", tags = { \"DSL\" })\n\t@PostMapping(value = \"/import-file\", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = \"application/json\")\n\tdefault R<App> importDSLFile(@RequestPart(\"file\") MultipartFile file, @RequestParam(\"dialect\") String dialect) {\n\t\tString content;\n\t\ttry {\n\t\t\tcontent = new String(file.getBytes(), StandardCharsets.UTF_8);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new SerializationException(\"Read dsl file failed, please check if the encoding of file is UTF_8 \");\n\t\t}\n\t\tDSLDialectType dialectType = DSLDialectType.fromValue(dialect)\n\t\t\t.orElseThrow(() -> new NotImplementedException(\"Unsupported dsl dialect: \" + dialect));\n\t\tApp app = getAdapter(dialectType).importDSL(content);\n\t\tapp = getAppSaver().save(app);\n\t\treturn R.success(app);\n\t}\n\n}\n","sourceCodeStart":81,"sourceCodeEnd":109,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/api/DSLAPI.java#L81-L109","documentation":"Thrown by DSLAPI.importDSLFile when reading the uploaded DSL file's bytes fails with an IOException. The library reads the file and decodes it as UTF-8; any I/O problem during getBytes() (truncated upload, unreadable temp storage) surfaces as this SerializationException. The message about UTF-8 encoding is somewhat misleading — the failure is the byte read, not the decoding.","triggerScenarios":"POSTing a multipart file to the DSL import endpoint where MultipartFile.getBytes() throws IOException — e.g. the uploaded part is empty/corrupted, disk I/O fails while spooling the temp file, or the underlying InputStream is already closed.","commonSituations":"Corrupted or truncated uploads, proxy/gateway mangling multipart bodies, container temp-dir issues (full disk, cleaned tmp), client closing the connection mid-upload.","solutions":["Verify the multipart request is well-formed and the file field name is 'file' with a valid binary part","Re-upload the file and confirm it is a complete UTF-8 text DSL file","Check server temp directory space/permissions for multipart spool files","Retry the upload; if persistent, inspect server logs for the underlying IOException"],"exampleFix":"// before (client)\ncurl -F \"file=@dsl.yaml\" -F \"dialect=dify\" /apps/import\n// after — ensure file is valid and fully transferred before upload\nfile dsl.yaml  # must be UTF-8 text, non-empty\n","handlingStrategy":"try-catch","validationCode":"if (file == null || file.isEmpty()) { throw new IllegalArgumentException(\"empty dsl file\"); }\nbyte[] bytes = file.getBytes(); // pre-check readability outside the API if possible","typeGuard":"boolean isReadable(MultipartFile f) { return f != null && !f.isEmpty(); }","tryCatchPattern":"try { api.importDSLFile(file, dialect); } catch (SerializationException e) { log.error(\"DSL upload read failed\", e); /* re-upload / surface 400 */ }","preventionTips":["Check file non-empty before upload","Ensure multipart limits (max-file-size) are not truncating uploads","Monitor server temp dir disk space","Verify network/proxy doesn't abort large uploads"],"tags":["file-read-failed","dsl","multipart-upload","io"],"backgroundTag":"file-read-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}