Home > Back-end >  TypeError: scheduler.do is not a function using blob.uploadStream
TypeError: scheduler.do is not a function using blob.uploadStream

Time:09-24

Used Package

I am trying to upload a blob to the azure blob storage using

blockBlobClient.uploadStream()

However, the package throws this error:

TypeError: scheduler.do is not a function
at BlockBlobClient.uploadStream (Clients.js:1954)

My code is:

    const blockBlobClient = sourceClient.getBlockBlobClient(blobName);
    const blockSize = 4 * 1024 * 1024; // the block size in the uploaded block blob
    const uploadBlobResponse = await blockBlobClient.uploadStream(file, blockSize, 20, {onProgress: (ev) => console.log(ev)});

How can I fix this error?

CodePudding user response:

The reason you're getting this error is because you're calling uploadStream method from a browser however it is only available in Node.JS runtime. From the code comments here:

  /**
   * ONLY AVAILABLE IN NODE.JS RUNTIME.
   *
   * Uploads a Node.js Readable stream into block blob.
   *
   * PERFORMANCE IMPROVEMENT TIPS:
   * * Input stream highWaterMark is better to set a same value with bufferSize
   *    parameter, which will avoid Buffer.concat() operations.
   *
   * @param stream - Node.js Readable stream
   * @param bufferSize - Size of every buffer allocated, also the block size in the uploaded block blob. Default value is 8MB
   * @param maxConcurrency -  Max concurrency indicates the max number of buffers that can be allocated,
   *                                 positive correlation with max uploading concurrency. Default value is 5
   * @param options - Options to Upload Stream to Block Blob operation.
   * @returns Response data for the Blob Upload operation.
   */
  public async uploadStream(

The method you would want to use for uploading is uploadBrowserData or uploadData when you are using this SDK in a browser-based application.

  • Related