{"record":{"id":"e82a8ff66483755a","repo":"Budibase/budibase","slug":"stream-to-upload-is-invalid-undefined","errorCode":null,"errorMessage":"Stream to upload is invalid/undefined","messagePattern":"Stream to upload is invalid/undefined","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/backend-core/src/objectStore/objectStore.ts","lineNumber":274,"sourceCode":"type StreamUploadInternalOptions = {\n  client: ReturnType<typeof ObjectStore>\n  bucket: string\n  filename: string\n  stream?: StreamTypes\n  type?: string | null\n  extra?: any\n}\n\nconst streamUploadInternal = async ({\n  client,\n  bucket,\n  filename,\n  stream,\n  type,\n  extra,\n}: StreamUploadInternalOptions) => {\n  if (!stream) {\n    throw new Error(\"Stream to upload is invalid/undefined\")\n  }\n\n  const contentType = resolveContentType(filename, type)\n  const key = sanitizeKey(filename)\n  const params = {\n    Bucket: bucket,\n    Key: key,\n    Body: stream,\n    ContentType: contentType,\n    ...(extra ?? {}),\n  }\n\n  const upload = new Upload({ client, params })\n  const details = await upload.done()\n\n  return {\n    details,\n    contentType,","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/backend-core/src/objectStore/objectStore.ts#L256-L292","documentation":"streamUploadInternal uploads a readable stream to the object store; it validates the stream argument first and throws this error when the stream is falsy (undefined/null). This prevents passing garbage to the S3 SDK's Upload, which would fail less clearly later.","triggerScenarios":"Calling upload/streamUploadInternal (directly or via upload of attachments, client libraries, etc.) where the caller passed no stream — e.g. reading a file that doesn't exist producing undefined, or a pipeline returning an empty value.","commonSituations":"fs.createReadStream on a nonexistent path upstream throwing/being swallowed; automation or API upload with an empty body; a previous transform step in a stream pipeline returning undefined; passing a string/Buffer path instead of an actual stream.","solutions":["Ensure a valid readable stream is passed (e.g. fs.createReadStream(existingPath) or a pipeline() result) before calling upload","Check that the source file/resource exists and is readable at upload time","Log the stream argument at the call site to confirm it is not undefined (common: wrong variable/path)","Pass a Buffer via Readable.from(buffer) if your data is in memory rather than a stream"],"exampleFix":"// before\nawait streamUpload({ bucket, filename: key, stream: maybeStream }) // undefined when file missing\n// after\nif (!fs.existsSync(filePath)) throw new Error(\"file missing\")\nawait streamUpload({ bucket, filename: key, stream: fs.createReadStream(filePath) })","handlingStrategy":"type-guard","validationCode":"function assertStream(stream) {\n  if (!stream || typeof stream.pipe !== \"function\") {\n    throw new Error(\"upload requires a readable stream\")\n  }\n}","typeGuard":"import { Readable } from \"stream\"\nfunction isReadableStream(value): value is Readable {\n  return value instanceof Readable || (value != null && typeof value.pipe === \"function\")\n}","tryCatchPattern":"try {\n  await upload({ bucket, filename: key, stream })\n} catch (err) {\n  if (String(err.message) === \"Stream to upload is invalid/undefined\") {\n    // check the call site: the stream source failed or was never created\n  }\n}","preventionTips":["Check the stream source (file exists, request body present) before calling upload","Guard helper functions with isReadableStream before passing streams down","Avoid swallowing errors from fs.createReadStream / pipeline setup upstream","Wrap in-memory data with Readable.from(buffer) rather than passing the buffer directly"],"tags":["object-store","upload","stream","validation"],"backgroundTag":"invalid-stream-argument","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}