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

    Class StorageObjectOps

    Storage object management interface

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

    This interface is accessed via RunloopSDK.storageObject. You should construct a RunloopSDK instance and use it from there:

    const runloop = new RunloopSDK();
    const storageObject = await runloop.storageObject.uploadFromFile("./my-file.txt", "my-file.txt");
    const objects = await runloop.storageObject.list();
    Index

    Methods

    • Create a new storage object. This is for advanced users and for basic operations you should use the StorageObjectOps.uploadFromFile uploadFromFile(), uploadFromText(), or uploadFromBuffer() methods instead.

      Parameters

      • params: ObjectCreateParams

        Parameters for creating the object.

      • Optionaloptions: RequestOptions<unknown> & { polling?: Partial<PollingOptions<ObjectView>> }

        Request options.

      Returns Promise<RunloopSDK.StorageObject>

      A StorageObject instance.

      const storageObject = await runloop.storageObject.create({
      name: 'my-file.txt',
      content_type: 'text',
      metadata: { project: 'demo' },
      });
      storageObject.uploadContent('Hello, World!');
      // this will mark the object as complete and make it read-only
      storageObject.complete();
    • Upload text content directly. This method handles the complete three-step upload process:

      1. Create object and get upload URL
      2. Upload text content to the provided URL
      3. Mark upload as complete

      Parameters

      • text: string

        The text content to upload.

      • name: string

        The name to use for the storage object.

      • Optionaloptions: RequestOptions<unknown> & { metadata?: Record<string, string> }

        Request options including metadata.

      Returns Promise<RunloopSDK.StorageObject>

      A StorageObject instance.

      const runloop = new RunloopSDK();
      const object = await runloop.storageObject.uploadFromText(
      'Hello, World!',
      'greeting.txt',
      { metadata: { type: 'greeting' } }
      );
    • Upload content from a Buffer (Node.js only). This method handles the complete three-step upload process:

      1. Create object and get upload URL
      2. Upload buffer content to the provided URL
      3. Mark upload as complete

      Parameters

      • buffer: Buffer

        The buffer containing the content to upload.

      • name: string

        The name to use for the storage object.

      • contentType: "binary" | "unspecified" | "text" | "gzip" | "tar" | "tgz"

        The content type of the buffer.

      • Optionaloptions: RequestOptions<unknown> & { metadata?: Record<string, string> }

        Request options including metadata.

      Returns Promise<RunloopSDK.StorageObject>

      A StorageObject instance.

      const runloop = new RunloopSDK();
      const buffer = Buffer.from('Binary data');
      const object = await runloop.storageObject.uploadFromBuffer(
      buffer,
      'data.bin',
      'unspecified',
      { metadata: { format: 'binary' } }
      );
    • Upload a local directory as a gzipped tarball (Node.js only). This method creates a tar archive of the directory contents, gzips it, and uploads it.

      Parameters

      • dirPath: string

        The path to the directory to upload.

      • params: Omit<ObjectCreateParams, "content_type">

        Parameters for creating the object.

      • Optionaloptions: RequestOptions<unknown>

        Request options.

      Returns Promise<RunloopSDK.StorageObject>

      A StorageObject instance.

      const runloop = new RunloopSDK();

      const object = await runloop.storageObject.uploadFromDir(
      './my-project',
      {
      name: 'my-project.tar.gz',
      ttl_ms: 3600000, // 1 hour
      metadata: { project: 'demo' }
      }
      );
      console.log(`Uploaded directory as ${object.id}`);