OpenFeign/feign · error · EncodeException
Writing file's ' ' content error
Error message
Writing file's '%s' content error
What it means
In SingleFileWriter.write (feign-form), the multipart writer fails while streaming the content of a java.io.File into the form output. The file was opened with FileInputStream but an IOException occurred during reading or writing (typical causes: file deleted or unreadable after metadata was written, disk/pipe I/O failure). The exception is rethrown as an EncodeException carrying the file name, so multipart encoding of the request aborts.
Solutions
- Verify the file exists and is readable before adding it to the multipart request
- Check disk space and output stream health if the read itself is failing
- Log/inspect the wrapped IOException cause for the root filesystem error
- Copy the file to a stable temporary location before encoding if it may change mid-write
Example fix
// before
client.upload(new File("/tmp/report.pdf"));
// after
File f = new File("/tmp/report.pdf");
if (!f.isFile() || !f.canRead()) throw new IllegalStateException("unreadable file: " + f);
client.upload(f); Defensive patterns
Strategy: validation
Validate before calling
static void requireReadable(File f) {
if (f == null || !f.isFile() || !f.canRead())
throw new IllegalArgumentException("file missing or unreadable: " + f);
} Try / catch
try {
client.upload(file);
} catch (EncodeException e) {
if (e.getMessage().contains("content error")) {
throw new UncheckedIOException((IOException) e.getCause());
}
throw e;
} Prevention
- Validate file existence/readability just before encoding
- Avoid encoding files on volatile storage or that another process may replace
- Prefer in-memory byte[] or a stable InputStream for uploads
When it happens
Trigger: write() called while encoding a single-file multipart part and the InputStream read fails (file missing, unreadable, closed) or the output stream write fails mid-copy.
Common situations: Encoding a java.io.File that was deleted or moved after the request was built; permission issues on the file; network-backed streams that fail mid-read.
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
- Output closing error
- SpringManyMultipartFilesReader does not support writing to…
- This form encoder has no delegate encoder, so it can only…
- ${e.getMessage()}
- is not a type supported by this encoder.
AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10).
Data as JSON: /api/errors/9277ccdead0b4312.
Report an issue: GitHub.
Appendix: source
Thrown at form/src/main/java/feign/form/multipart/SingleFileWriter.java:51
public boolean isApplicable(Object value) {
return value instanceof File;
}
@Override
protected void write(Output output, String key, Object value) throws EncodeException {
val file = (File) value;
writeFileMetadata(output, key, file.getName(), null);
try (InputStream input = new FileInputStream(file)) {
val buf = new byte[4096];
int length = input.read(buf);
while (length > 0) {
output.write(buf, 0, length);
length = input.read(buf);
}
} catch (IOException ex) {
val message = String.format("Writing file's '%s' content error", file.getName());
throw new EncodeException(message, ex);
}
}
}
View on GitHub (pinned to e2a1e27560)