Class: BatchUpload

BatchUpload(opts)

The BatchUpload class allows to upload Blob objets to a Nuxeo Platform instance
using the batch upload API.

It creates and maintains a batch id from the Nuxeo Platform instance.

Cannot directly be instantiated

Constructor

new BatchUpload(opts)

Creates a BatchUpload.

Parameters:
Name Type Description
opts object

The configuration options.

Properties
Name Type Attributes Default Description
nuxeo string

The Nuxeo object linked to this BatchUpload object.

concurrency Number <optional>
5

Number of concurrent uploads.

Source:
Example
var Nuxeo = require('nuxeo')
var nuxeo = new Nuxeo({
 baseURL: 'http://localhost:8080/nuxeo',
 auth: {
   method: 'basic',
   username: 'Administrator',
   password: 'Administrator'
 }
});
var batch = nuxeo.batchUpload();
var nuxeoBlob = new Nuxeo.Blob(...);
batch.upload(nuxeoBlob)
  .then(function(res) {
    // res.blob instanceof BatchBlob === true
  })
  .catch(function(error) {
    throw new Error(error);
  });

Methods

cancel() → {Promise}

Cancels a BatchUpload.

Source:
Returns:

A Promise object resolved with the BatchUpload itself.

Type
Promise

done() → {Promise}

Wait for all the current uploads to be finished. Note that it won't wait for uploads added after done() being call.
If an uploaded is added, you should call again done().
The BatchUpload#isFinished method can be used to know if the batch is finished.

Source:
Returns:

A Promise object resolved when all the current uploads are finished.

Type
Promise
Example
...
nuxeoBatch.upload(blob1, blob2, blob3);
nuxeoBatch.done()
  .then(function(res) {
    // res.batch === nuxeoBatch
    // res.blobs[0] is the BatchBlob object related to blob1
    // res.blobs[1] is the BatchBlob object related to blob2
    // res.blobs[2] is the BatchBlob object related to blob3
  })
  .catch(function(error) {
    throw new Error(error);
  });

fetchBlob() → {Promise}

Fetches a blob at a given index from the batch.

Source:
Returns:

A Promise object resolved with the BatchUpload itself and the BatchBlob.

Type
Promise

fetchBlobs() → {Promise}

Fetches the blobs from the batch.

Source:
Returns:

A Promise object resolved with the BatchUpload itself and the BatchBlobs.

Type
Promise

isFinished() → {Boolean}

Returns whether the BatchUpload is finished, ie. has uploads running, or not.

Source:
Returns:

true if the BatchUpload is finished, false otherwise.

Type
Boolean

removeBlob() → {Promise}

Removes a blob at a given index from the batch.

Source:
Returns:

A Promise object resolved with the result of the DELETE request.

Type
Promise

upload(…blobs) → {Promise}

Upload one or more blobs.

Parameters:
Name Type Attributes Description
blobs Blob <repeatable>

Blobs to be uploaded.

Source:
Returns:

A Promise object resolved when all blobs are uploaded.

Type
Promise
Example
...
nuxeoBatch.upload(blob1, blob2, blob3)
  .then(function(res) {
    // res.batch === nuxeoBatch
    // res.blobs[0] is the BatchBlob object related to blob1
    // res.blobs[1] is the BatchBlob object related to blob2
    // res.blobs[2] is the BatchBlob object related to blob3
  })
  .catch(function(error) {
    throw new Error(error);
  });