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

  1. Build the content value with JSON.stringify(obj) on the client rather than writing JSON by hand.
  2. If you have no structured metadata, omit the 'content' field entirely.
  3. Log the exact content string and run it through a JSON linter to find the syntax error.
  4. 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

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


AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12). Data as JSON: /api/errors/5ab89968a31f5593. Report an issue: GitHub.