@runloop/api-client - v1.4.0
    Preparing search index...

    Class StorageObject

    Object-oriented interface for working with Storage Objects.

    The StorageObject class provides a high-level API for managing storage objects, which are files stored in Runloop's object storage. Storage objects can be uploaded, downloaded, and managed with metadata.

    import { RunloopSDK } from '@runloop/api-client-ts';

    const runloop = new RunloopSDK();
    const storageObject = await runloop.storageObject.uploadFromFile(
    './my-file.txt',
    'my-file.txt',
    { metadata: { project: 'demo' } },
    );
    const text = await storageObject.downloadAsText();
    Index

    Accessors

    Methods

    • Create a new Storage Object. This method returns a StorageObject instance that you can use to upload content.

      You should use the uploadFromFile() or uploadFromBuffer() methods to upload content and handle the complete process for you. If you need more control, you can use the uploadContent() method.

      To upload content:

      1. To upload you call uploadContent() or use the getDownloadUrl() method to get the upload URL and upload the content manually.
      2. You must call complete() to mark the upload as complete.

      Parameters

      • client: Runloop

        The Runloop client instance

      • params: ObjectCreateParams

        Parameters for creating the object

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<RunloopSDK.StorageObject>

      A StorageObject instance with upload URL

      const runloop = new RunloopSDK();
      // Step 1: Create object
      const object = await runloop.storageObject.create({
      name: 'my-file.txt',
      content_type: 'text',
      });

      // Step 2: Upload content
      await object.uploadContent('File contents');

      // Step 3: Mark as complete
      await object.complete();
    • Parameters

      • client: Runloop
      • dirPath: string
      • params: Omit<ObjectCreateParams, "content_type">
      • Optionaloptions: RequestOptions<unknown> & {
            ignore?: string[] | IgnoreMatcher;
            dockerignorePath?: string;
        }
        • Optionalignore?: string[] | IgnoreMatcher

          Optional ignore configuration for the directory:

          • an IgnoreMatcher instance, or
          • an array of docker-style glob patterns (as in .dockerignore)
        • OptionaldockerignorePath?: string

          Optional path to a specific .dockerignore-style file to use instead of the default <dirPath>/.dockerignore.

      Returns Promise<RunloopSDK.StorageObject>

    • Get the complete object data from the API.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<ObjectView>

      The object data

      const runloop = new RunloopSDK();
      const object = runloop.storageObject.fromId('object-123');
      const info = await object.getInfo();
      console.log(`Name: ${info.name}, Size: ${info.size}, Type: ${info.content_type}`);
    • Upload content to the storage object using the presigned URL. This is a convenience method that handles the HTTP PUT request.

      Note: For large files or binary content, you may want to use the uploadUrl directly with your own upload logic.

      When this is done call complete() to mark the upload as complete.

      Parameters

      • content: string | Buffer<ArrayBufferLike>

        The content to upload (string or Buffer)

      Returns Promise<void>

      Promise that resolves when upload is complete

      const runloop = new RunloopSDK();
      const object = await runloop.storageObject.create({
      name: 'data.txt',
      content_type: 'text',
      });
      await object.uploadContent('Hello, World!');
      await object.complete();
    • Mark the object's upload as complete, transitioning it from UPLOADING to READ_ONLY state. Call this after you've finished uploading content via the upload URL.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<void>

      Promise that resolves when the upload is marked as complete

    • Get a presigned download URL for this object. The URL will be valid for the specified duration (default: 1 hour).

      Parameters

      • OptionaldurationSeconds: number

        How long the URL should be valid (default: 3600)

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<ObjectDownloadURLView>

      Download URL information

      const runloop = new RunloopSDK();
      const object = runloop.storageObject.fromId('object-123');
      const { download_url } = await object.getDownloadUrl(3600); // Valid for 1 hour
      console.log(`Download URL: ${download_url}`);
    • Download the content of this object as text. This is a convenience method that fetches the download URL and retrieves the content.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<string>

      The object content as a string

      const runloop = new RunloopSDK();
      const object = runloop.storageObject.fromId('object-123');
      const content = await object.downloadAsText();
      console.log(content);
    • Download the content of this object as a Buffer. This is a convenience method that fetches the download URL and retrieves the content.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<Buffer<ArrayBufferLike>>

      The object content as a Buffer

      const runloop = new RunloopSDK();
      const object = runloop.storageObject.fromId('object-123');
      const buffer = await object.downloadAsBuffer();
      fs.writeFileSync('downloaded.bin', buffer);
    • Delete this object. This action is irreversible.

      Parameters

      • Optionaloptions: RequestOptions<unknown>

        Request options

      Returns Promise<void>

      Promise that resolves when the object is deleted