DOIP Client Library - JavaScript Version
    Preparing search index...

    Class ElementWithBody

    This helper class can be used to create a new element with a body to attach to a Digital Object.

    const image = await fetch('https://www.cordra.org/assets/img/favicon.ico', { method: 'GET' });
    const binaryElement = new ElementWithBody({
    id: "binaryElement",
    body: image.body,
    type: "image/vnd.microsoft.icon",
    attributes: {
    filename: "favicon.ico"
    }
    });
    const textFileElement = new ElementWithBody({
    id: "textFileElement",
    body: "This text body will be stored as a file called foo.txt",
    type: "application/text",
    attributes: {
    filename: "foo.txt"
    }
    });
    const digitalObject = {
    type: 'Document',
    elements: [ textFileElement, binaryElement ],
    attributes: {
    content: { name: 'Element Example' }
    }
    };
    const result = await client.create(digitalObject);
    console.log(result.elements);

    Implements

    Index

    Constructors

    • Constructs an ElementWithBody.

      Parameters

      • element: Omit<Element, "body"> & {
            body?:
                | null
                | string
                | ArrayBuffer
                | ArrayBufferView<ArrayBuffer>
                | Blob
                | ReadableStream<Uint8Array<ArrayBuffer>>;
        }

        The Element, with the usual "id", "type", "length", and "attributes" properties, and where the "body" property can be a ReadableStream or another way to provide the bytes (Blob, ArrayBuffer, ArrayBufferView, or string).

      Returns ElementWithBody

    Properties

    id: string

    The identifier of the element within the digital object. This is used to reference the element when retrieving it.

    type?: string

    The MIME type of the element's content. For example, "application/pdf" or "image/jpeg".

    length?: number

    The length of the element's content in bytes.

    attributes?: Record<string, Json>

    Additional metadata about the element. This can include information like filename.

    bodySegment: InDoipSegment

    Accessors

    • get body(): ReadableStream<Uint8Array<ArrayBuffer>>

      The binary content of the element as a readable stream. This is typically present when retrieving an element or when creating/updating an element with streaming content. When making a request, ElementWithBody can be used to provide the element bytes using other JavaScript types.

      Returns ReadableStream<Uint8Array<ArrayBuffer>>

    • get bodyUsed(): boolean

      Returns boolean

    Methods

    • Returns Promise<ArrayBuffer>

    • Returns Promise<Uint8Array<ArrayBuffer>>

    • Returns Promise<Blob>

    • Returns Promise<Json>

    • Returns Promise<string>

    • Returns Promise<FormData>

    • In situations where we can't just use ReadableStream -- namely, browsers which don't support ReadableStream requests in fetch -- we may want to know whether we had a ReadableStream or a Blob (in particular, a File) in order to construct a request with the minimum of reading things into memory.

      Returns Blob | ReadableStream<Uint8Array<ArrayBuffer>>