Options
All
  • Public
  • Public/Protected
  • All
Menu

Provides filesystem-access abstractions for the browser and node, and helpers for uploading them to the Livepeer API for creating the NFTs.

remarks

In the browser: you would typically use the pickFile method for opening a file picker and then uploadFile for sending the file contents to a URL obtained via Api.requestUploadUrl.

remarks

In node.js: you should use openFile or useFile instead, already passing the full path of the file that the user should have provided to your application somehow. After that, you can use the same uploadFile method to upload the file contents to the Livepeer API.

Hierarchy

  • Uploader

Index

Constructors

Methods

  • openFile(path: string): ReadStream
  • Node-only: Opens the file at the given path for reading.

    remarks

    This method is only supported in node.js. It will throw an error if called from a different environment like the browser.

    Parameters

    • path: string

      The full path of the file to open.

    Returns ReadStream

    A fs.ReadStream with the file contents.

  • pickFile(): Promise<File>
  • Browser-only: Opens the file picker from the operating system for the user to select a video file to upload.

    remarks

    This method is only supported in the browser. It will throw an error if called from a different environment like node.js.

    remarks

    The Livepeer VOD API currently only supports MP4 as a container format, so the file picker will only allow selecting files with the .mp4 extension.

    Returns Promise<File>

    A promise that will be resolved with the File that the user picks in the file picker.

  • uploadFile(url: string, content: File | ReadableStream, reportProgress?: (progress: number) => void, mimeType?: string): Promise<void>
  • Uploads a file to the Livepeer API using a direct upload URL obtained via Api.requestUploadUrl.

    remarks

    This is simply a proxy to VodApi.uploadFile, exposed here as a helper so you don't need to interact with the VodApi class directly as well.

    Parameters

    • url: string

      The direct upload URL obtained via Api.requestUploadUrl.

    • content: File | ReadableStream

      The file contents to upload.

    • Optional reportProgress: (progress: number) => void
        • (progress: number): void
        • Parameters

          • progress: number

          Returns void

    • Optional mimeType: string

    Returns Promise<void>

    A promise that will be completed when the upload is done.

  • useFile<T>(path: string, handler: (file: ReadStream) => T | PromiseLike<T>): Promise<T>
  • Node-only: Opens a file for reading and passes it to the given handler, closing the read stream as soon as the handler is done.

    remarks

    This method is only supported in node.js. It will throw an error if called from a different environment like the browser.

    remarks

    This is only a helpful abstraction on top of openFile so you don't need to handle the fs.ReadStream lifecycle yourself.

    Type parameters

    • T

    Parameters

    • path: string

      The full path of the file to open.

    • handler: (file: ReadStream) => T | PromiseLike<T>

      A function that will be called with the fs.ReadStream. If it returns a promise, the file read stream will only be closed when the promise is resolved.

        • (file: ReadStream): T | PromiseLike<T>
        • Parameters

          • file: ReadStream

          Returns T | PromiseLike<T>

    Returns Promise<T>

    The same value that was returned by the handler, maybe wrapped in a promise.

Generated using TypeDoc