{"record":{"id":"a801a8db1ad099bb","repo":"hcengineering/platform","slug":"file-of-this-type-stat-contenttype-cannot-be","errorCode":null,"errorMessage":"File of this type (${stat.contentType}) cannot be converted","messagePattern":"File of this type \\((.+?)\\) cannot be converted","errorType":"http","errorClass":"ApiError","httpStatus":400,"severity":"error","filePath":"services/print/pod-print/src/server.ts","lineNumber":255,"sourceCode":"      res.contentType('application/json')\n      res.send({ id: printId })\n    })\n  )\n\n  app.get(\n    '/convert/:file',\n    wrapRequest(async (req, res, wsUuid) => {\n      const convertableFormats = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document']\n      const ctx = req.ctx\n      const file = req.params.file\n      const stat = await storageAdapter.stat(ctx, wsUuid, file)\n\n      if (stat === undefined) {\n        throw new ApiError(404, `File ${file} not found`)\n      }\n\n      if (!convertableFormats.includes(stat.contentType)) {\n        throw new ApiError(400, `File of this type (${stat.contentType}) cannot be converted`)\n      }\n\n      const convertId = getConvertId(file, stat.etag)\n      const convertStats = await storageAdapter.stat(ctx, wsUuid, convertId)\n\n      if (convertStats === undefined) {\n        const originalFile = await storageAdapter.read(ctx, wsUuid, file)\n\n        if (originalFile === undefined) {\n          throw new ApiError(404, `File ${file} not found`)\n        }\n\n        const htmlRes = await ctx.with('convertToHtml', {}, () => convertToHtml(Buffer.concat(originalFile as any)))\n\n        if (htmlRes === undefined) {\n          throw new ApiError(400, 'Failed to convert')\n        }\n","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/print/pod-print/src/server.ts#L237-L273","documentation":"Only DOCX files (content type application/vnd.openxmlformats-officedocument.wordprocessingml.document) are supported for HTML conversion. If the stored object's content type is anything else — PDF, image, legacy .doc, plain text — the endpoint rejects it with this 400 ApiError.","triggerScenarios":"GET /convert/:file on a file whose stored contentType is not the DOCX MIME type — e.g. uploading a .doc, .odt, .pdf, or a .docx that was uploaded with a wrong/generic content type like application/octet-stream.","commonSituations":"Upload pipeline stores files with application/octet-stream because the client didn't set MIME type; older files stored before content-type tracking; users renaming .doc to .docx; legacy Word formats.","solutions":["Upload the file as genuine .docx and ensure the upload sets the correct DOCX MIME type.","Convert legacy .doc/.odt files to .docx before uploading.","If the file IS docx but stored with the wrong contentType, re-upload it with the correct MIME type (stored contentType is authoritative, not the filename)."],"exampleFix":"// before\nform.append('file', docxFile, { type: 'application/octet-stream' })\n// after\nform.append('file', docxFile, { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' })","handlingStrategy":"validation","validationCode":"const DOCX_MIME = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'\nfunction assertConvertibleFile (file: { contentType: string, name: string }): void {\n  if (!file.name.toLowerCase().endsWith('.docx')) throw new Error('only .docx files can be converted')\n  if (file.contentType !== DOCX_MIME) throw new Error(`stored contentType ${file.contentType} is not DOCX`)\n}","typeGuard":"function isDocxFile (f: { contentType: string }): boolean {\n  return f.contentType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'\n}","tryCatchPattern":"try {\n  const res = await fetch(`/convert/${encodeURIComponent(fileKey)}`, { headers })\n  if (!res.ok) {\n    const body = await res.json()\n    if (body.code === 400 && /cannot be converted/.test(body.message)) {\n      throw new Error(`Unsupported format: ${body.message} — convert to .docx first`)\n    }\n    throw new Error(body.message)\n  }\n  return await res.json()\n} catch (err) { /* handle */ }","preventionTips":["Always set the DOCX MIME type explicitly at upload time (never rely on browser sniffing).","Convert .doc/.odt to .docx before upload; a renamed extension is not enough.","Validate MIME type client-side before upload with an accept-list in the file picker."],"tags":["http-400","file-format","docx","content-type"],"backgroundTag":"unsupported-file-format","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}