Budibase/budibase · error

Stream to upload is invalid/undefined

Error message

Stream to upload is invalid/undefined

What it means

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.

Source

Thrown at packages/backend-core/src/objectStore/objectStore.ts:274

type StreamUploadInternalOptions = {
  client: ReturnType<typeof ObjectStore>
  bucket: string
  filename: string
  stream?: StreamTypes
  type?: string | null
  extra?: any
}

const streamUploadInternal = async ({
  client,
  bucket,
  filename,
  stream,
  type,
  extra,
}: StreamUploadInternalOptions) => {
  if (!stream) {
    throw new Error("Stream to upload is invalid/undefined")
  }

  const contentType = resolveContentType(filename, type)
  const key = sanitizeKey(filename)
  const params = {
    Bucket: bucket,
    Key: key,
    Body: stream,
    ContentType: contentType,
    ...(extra ?? {}),
  }

  const upload = new Upload({ client, params })
  const details = await upload.done()

  return {
    details,
    contentType,

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Ensure a valid readable stream is passed (e.g. fs.createReadStream(existingPath) or a pipeline() result) before calling upload
  2. Check that the source file/resource exists and is readable at upload time
  3. Log the stream argument at the call site to confirm it is not undefined (common: wrong variable/path)
  4. Pass a Buffer via Readable.from(buffer) if your data is in memory rather than a stream

Example fix

// before
await streamUpload({ bucket, filename: key, stream: maybeStream }) // undefined when file missing
// after
if (!fs.existsSync(filePath)) throw new Error("file missing")
await streamUpload({ bucket, filename: key, stream: fs.createReadStream(filePath) })
Defensive patterns

Strategy: type-guard

Validate before calling

function assertStream(stream) {
  if (!stream || typeof stream.pipe !== "function") {
    throw new Error("upload requires a readable stream")
  }
}

Type guard

import { Readable } from "stream"
function isReadableStream(value): value is Readable {
  return value instanceof Readable || (value != null && typeof value.pipe === "function")
}

Try / catch

try {
  await upload({ bucket, filename: key, stream })
} catch (err) {
  if (String(err.message) === "Stream to upload is invalid/undefined") {
    // check the call site: the stream source failed or was never created
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/e82a8ff66483755a. Report an issue: GitHub.