{"record":{"id":"cf023c6b2ddce1f9","repo":"Budibase/budibase","slug":"cannot-import-a-non-text-based-file","errorCode":null,"errorMessage":"Cannot import a non-text based file.","messagePattern":"Cannot import a non-text based file\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/backups/imports.ts","lineNumber":135,"sourceCode":"      automation.definition.trigger.inputs = {\n        schemaUrl: old.schemaUrl.replace(oldDevAppId, devId),\n        triggerUrl: old.triggerUrl.replace(oldProdAppId, prodAppId),\n      }\n    }\n    automation.appId = devId\n    toSave.push(automation)\n  }\n  await db.bulkDocs(toSave)\n}\n\n/**\n * This function manages temporary template files which are stored by Koa.\n * @param template The template object retrieved from the Koa context object.\n * @returns Returns a fs read stream which can be loaded into the database.\n */\nasync function getTemplateStream(template: TemplateType) {\n  if (template.file && template.file.type !== \"text/plain\") {\n    throw new Error(\"Cannot import a non-text based file.\")\n  }\n  if (template.file) {\n    return fs.createReadStream(template.file.path)\n  } else if (template.key) {\n    const [type, name] = template.key.split(\"/\")\n    const tmpPath = await downloadTemplate(type, name)\n    return fs.createReadStream(join(tmpPath, name, \"db\", \"dump.txt\"))\n  } else {\n    throw new Error(\"Either file or key is required.\")\n  }\n}\n\nexport async function untarFile(file: { path: string }) {\n  const tmpPath = join(budibaseTempDir(), uuid())\n  await fsp.mkdir(tmpPath)\n  // extract the tarball\n  await tar.extract({\n    cwd: tmpPath,","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/backups/imports.ts#L117-L153","documentation":"getTemplateStream rejects uploaded template files whose MIME type is not text/plain, because app template imports are text-based DB dumps (dump.txt), not binary archives. Any binary upload passed as `template.file` is rejected before a read stream is opened.","triggerScenarios":"importApp called with a template.file whose `type` is e.g. application/zip, application/octet-stream, or an empty/missing type — typically uploading a binary export archive directly instead of a plain-text export, or a client sending the file without the correct content type.","commonSituations":"Uploading a .tar.gz export into an import endpoint expecting a text dump; curl uploads missing -F type annotations so the browser/koa reports octet-stream; mixing up the import endpoints that accept encrypted/binary packages vs text templates.","solutions":["Upload a plain-text export (dump.txt style) rather than a binary archive","Set the correct file MIME type (text/plain) when uploading, e.g. ensure the multipart part declares it","Use the app import endpoint that accepts tar/zip exports instead of the template import path","Re-export the app using the export feature that produces the text-based DB dump"],"exampleFix":"// before\ncurl -F \"file=@export.tar.gz;type=application/zip\" /api/apps/import  // throws\n// after\ncurl -F \"file=@dump.txt;type=text/plain\" /api/templates/import","handlingStrategy":"validation","validationCode":"if (template.file && template.file.type !== \"text/plain\") {\n  throw new Error(\"Expected a text/plain export file\")\n}","typeGuard":"function isTextFile(f: { type?: string } | undefined): f is { type: \"text/plain\" } {\n  return !!f && f.type === \"text/plain\"\n}","tryCatchPattern":"try {\n  await importApp(template)\n} catch (err: any) {\n  if (err.message.includes(\"non-text based file\")) {\n    // request a text-based export instead\n  } else {\n    throw err\n  }\n}","preventionTips":["Upload text/plain dumps for template imports","Set explicit MIME types in multipart forms","Inspect file type with the `file` utility before uploading"],"tags":["import","file-type","validation"],"backgroundTag":"unsupported-file-type","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}