RocketChat/Rocket.Chat · error · Meteor.Error
invalid-field-content
invalid-field-content
Error message
invalid-field-content
What it means
Thrown by POST rooms.upload when the optional 'content' form field is present but JSON.parse fails. The 'content' field lets callers attach structured metadata (e.g. message attachments) alongside the binary file; if supplied it must be valid JSON.
Source
Thrown at apps/meteor/server/api/v1/rooms.ts:294
field: 'file',
maxSize: settings.get<number>('FileUpload_MaxFileSize'),
});
if (!file) {
throw new Meteor.Error('error-no-file-uploaded', 'No file was uploaded');
}
const expiresAt = new Date();
expiresAt.setHours(expiresAt.getHours() + 24);
let content;
if (fields.content) {
try {
content = JSON.parse(fields.content);
} catch (e) {
console.error(e);
throw new Meteor.Error('invalid-field-content');
}
}
const details = {
name: file.filename,
size: file.size,
type: file.mimetype,
rid: this.urlParams.rid,
userId: this.userId,
content,
expiresAt,
};
// TODO: In the future, we should isolate file receival from storage and post-processing.
const fileStore = FileUpload.getStore('Uploads');
const uploadedFile = await fileStore.insert(details, file.tempFilePath);
uploadedFile.path = FileUpload.getPath(`${uploadedFile._id}/${encodeURI(uploadedFile.name || '')}`);View on GitHub (pinned to f9d3ec372b)
Solutions
- Build the content value with JSON.stringify(obj) on the client rather than writing JSON by hand.
- If you have no structured metadata, omit the 'content' field entirely.
- Log the exact content string and run it through a JSON linter to find the syntax error.
- Ensure the field isn't being base64'd or URL-encoded twice.
Example fix
// before
form.append('content', "{attachments: ['x']}"); // invalid JSON
// after
form.append('content', JSON.stringify({ attachments: ['x'] })); Defensive patterns
Strategy: validation
Validate before calling
let contentStr: string | undefined;
if (contentObj !== undefined) {
contentStr = JSON.stringify(contentObj);
JSON.parse(contentStr); // throws now, not on the server
}
if (contentStr) form.append('content', contentStr); Type guard
function isJsonString(s: unknown): boolean {
if (typeof s !== 'string') return false;
try { JSON.parse(s); return true; } catch { return false; }
} Try / catch
try {
await rest.post(url, form);
} catch (e) {
if (isMeteorError(e, 'invalid-field-content')) {
// re-stringify content via JSON.stringify and retry
} else throw e;
} Prevention
- Never hand-write the content JSON — always JSON.stringify.
- Omit 'content' when you have no structured metadata.
- Lint the string with JSON.parse client-side before sending.
When it happens
Trigger: Multipart upload to rooms.upload/:rid where fields.content is set but is malformed JSON — trailing commas, single quotes, unquoted keys, truncated payload, or a non-JSON string.
Common situations: Stringifying an object incompletely; passing a hand-written JSON string with a typo; double-encoding (JSON.stringify of an already-stringified value then truncation); locale number formatting leaking into JSON.
Related errors
- error-message-size-exceeded
- Failed to parse app.json: ${e instanceof Error ? e.message :
- The "${name}" parameter must be a valid date.
- error-duplicate-role-names-not-allowed
- error-room-not-found
AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12).
Data as JSON: /api/errors/5ab89968a31f5593.
Report an issue: GitHub.