Tela SDK for JavaScript
    Preparing search index...

    Class TelaFile

    Represents a file with support for various types including URLs, binary data, streams, and Blobs.

    // Using a URL string
    const urlFile = new TelaFile("https://example.com/file.png", { range: { start: 0, end: 1024 } })

    // Using a Uint8Array (buffer)
    const buffer = new Uint8Array(['binary data...'])
    const bufferFile = new TelaFile(buffer)

    // Using a ReadStream
    import { createReadStream } from 'fs'
    const readStream = createReadStream('path/to/file')
    const streamFile = new TelaFile(readStream)

    // Using a ReadableStream
    const readableStream = new ReadableStream({
    start(controller) {
    controller.enqueue(new TextEncoder().encode('Hello, world!'))
    controller.close()
    }
    })
    const readableStreamFile = new TelaFile(readableStream)

    // Using a Blob (in environments that support Blob)
    const blob = new Blob(['file content'], { type: 'text/plain' })
    const blobFile = new TelaFile(blob)

    // Using a File (in browser environments)
    const file = new File(['file content'], 'filename.txt', { type: 'text/plain' })
    const fileInstance = new TelaFile(file)

    // Using multiple files in a collection
    const files = [
    new TelaFile("https://example.com/file1.pdf", { range: [0, 1] }),
    new TelaFile("https://example.com/file2.pdf", { range: [1, 2] })
    ]
    // Pass the array of files to a variable
    const result = await tela.completions.create({
    canvasId: "your-canvas-id",
    variables: {
    documents: files
    }
    })
    Index

    Constructors

    • Creates an instance of TelaFile.

      Parameters

      • file: string | Blob | File

        The source of the file. Can be a URL string, Uint8Array, ReadableStream, ReadStream, Blob, or File.

      • Optionaloptions: BaseTelaFileOptions

        Optional configuration options such as byte range.

      Returns TelaFile

      If the provided URL is not valid.

      If the provided file is empty.

    • Parameters

      Returns TelaFile

    Accessors

    • get isURL(): boolean

      Determines whether the file source is a valid URL.

      Returns boolean

      true if the file source is a valid URL string, otherwise false.

    • get isVaultReference(): boolean

      Determines whether the file source is a valid Vault reference.

      Returns boolean

      true if the file source is a valid Vault reference, otherwise false.

    • get name(): string | null

      Gets the name of the file.

      Returns string | null

      The name of the file if available, otherwise null.

    • get options(): TelaFileOptions

      Retrieves the options provided during instantiation.

      Returns TelaFileOptions

      The TelaFileOptions or an empty object if none were provided.

    • get size(): number | null

      Gets the size of the file in bytes.

      Returns number | null

      The size of the file if available, otherwise null.

    • get type(): string | null

      Gets the type of the file.

      Returns string | null

      The type of the file if available, otherwise null.

    Methods

    • Retrieves the content of the file in a format suitable for uploading.

      • If the file is a URL, it returns the URL string.
      • If the file is a Uint8Array, it converts it to a File object.
      • If the file is a ReadStream or ReadableStream, it calculates the size and returns a stream.

      Returns Promise<string | ReadableStream<any> | Blob | File>

      A promise that resolves to the uploadable content.