alibaba/spring-ai-alibaba · error · SerializationException

Read dsl file failed, please check if the encoding of file i

Error message

Read dsl file failed, please check if the encoding of file is UTF_8 

What it means

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.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/api/DSLAPI.java:99

	@Operation(summary = "import app from dsl", tags = { "DSL" })
	@PostMapping(value = "/import", produces = "application/json")
	default R<App> importDSL(@RequestBody DSLParam param) {
		DSLDialectType dialectType = DSLDialectType.fromValue(param.getDialect())
			.orElseThrow(() -> new NotImplementedException("Unsupported dsl dialect: " + param.getDialect()));
		App app = getAdapter(dialectType).importDSL(param.getContent());
		app = getAppSaver().save(app);
		return R.success(app);
	}

	@Operation(summary = "import app from dsl file ", tags = { "DSL" })
	@PostMapping(value = "/import-file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = "application/json")
	default R<App> importDSLFile(@RequestPart("file") MultipartFile file, @RequestParam("dialect") String dialect) {
		String content;
		try {
			content = new String(file.getBytes(), StandardCharsets.UTF_8);
		}
		catch (IOException e) {
			throw new SerializationException("Read dsl file failed, please check if the encoding of file is UTF_8 ");
		}
		DSLDialectType dialectType = DSLDialectType.fromValue(dialect)
			.orElseThrow(() -> new NotImplementedException("Unsupported dsl dialect: " + dialect));
		App app = getAdapter(dialectType).importDSL(content);
		app = getAppSaver().save(app);
		return R.success(app);
	}

}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Verify the multipart request is well-formed and the file field name is 'file' with a valid binary part
  2. Re-upload the file and confirm it is a complete UTF-8 text DSL file
  3. Check server temp directory space/permissions for multipart spool files
  4. Retry the upload; if persistent, inspect server logs for the underlying IOException

Example fix

// before (client)
curl -F "file=@dsl.yaml" -F "dialect=dify" /apps/import
// after — ensure file is valid and fully transferred before upload
file dsl.yaml  # must be UTF-8 text, non-empty
Defensive patterns

Strategy: try-catch

Validate before calling

if (file == null || file.isEmpty()) { throw new IllegalArgumentException("empty dsl file"); }
byte[] bytes = file.getBytes(); // pre-check readability outside the API if possible

Type guard

boolean isReadable(MultipartFile f) { return f != null && !f.isEmpty(); }

Try / catch

try { api.importDSLFile(file, dialect); } catch (SerializationException e) { log.error("DSL upload read failed", e); /* re-upload / surface 400 */ }

Prevention

When it happens

Trigger: 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.

Common situations: Corrupted or truncated uploads, proxy/gateway mangling multipart bodies, container temp-dir issues (full disk, cleaned tmp), client closing the connection mid-upload.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/0f24add509f796f4. Report an issue: GitHub.