Skip to content

@ubstream/ubstream-node-client-sdk / Exports / MediasClient

Class: MediasClient

This class provides access to methods concerning medias.

Hierarchy

  • AbstractClient

MediasClient

Table of contents

Properties

Methods

Properties

authz

Readonly authz: MediasAuthzClient

Attribute to access all methods concerning authorizations of medias.


documents

Readonly documents: MediasDocumentsClient

Attribute to access all methods concerning medias.


metadata

Readonly metadata: MediasMetadataClient

Attribute to access all methods concerning metadata of medias.

Methods

changeMediaThumbs

changeMediaThumbs(mediaId, formData): Promise<IPublicMediaThumbUpdateResultDataWithRequestId>

Parameters

Name Type Description
mediaId string The uuid of the targeted media.
formData IFormData The form data containing the file to upload.

Returns

Promise<IPublicMediaThumbUpdateResultDataWithRequestId>

Promise object representing information concerning the media for which the thumb has been modified, the requestId and diagnoses of the operation.

Summary

Change the thumb of all documents of a media.

Example

const file = typeof input === 'string' ? fs.createReadStream(input) : input;
const formData = new FormData(); // https://www.npmjs.com/package/form-data
formData.append('file', file);
const result = await client.medias.changeMediaThumbs("media_id", formData);

createLink(libraryId, collectionId, body): Promise<IPublicMediaDocumentUploadResultDataWithRequestId>

Parameters

Name Type Description
libraryId string The uuid of the targeted library.
collectionId string The uuid of the target collection.
body IPublicCreateMediaLinkParams The body of the link.

Returns

Promise<IPublicMediaDocumentUploadResultDataWithRequestId>

Promise object representing the new link, the requestId.

Summary

Create a new link.

Example

const linkParams : IPublicCreateMediaLinkParams = {
     url: "www.test.com",
     title: "test",
};
const linkCreated = await client.medias.createLink("library_id", "collection_id", linkParams);

createMediaFromUrl

createMediaFromUrl(libraryId, collectionId, body): Promise<IPublicMediaDocumentUploadResultDataWithRequestId>

Parameters

Name Type Description
libraryId string The uuid of the targeted library.
collectionId string The uuid of the target collection.
body IPublicMediaDocumentUploadFromUrlForm The body of the media to create.

Returns

Promise<IPublicMediaDocumentUploadResultDataWithRequestId>

Promise object representing the new media, the requestId.

Summary

Create a new media from url.

Example

const mediaParams : IPublicMediaDocumentUploadFromUrlForm = {
     url: "www.test.com/image.png",
};
const mediaCreated = await client.medias.createMediaFromUrl("library_id", "collection_id", mediaParams);

deleteMedia

deleteMedia(mediaId): Promise<IPublicDeleteMediaQuery>

Parameters

Name Type Description
mediaId string The uuid of the targeted media.

Returns

Promise<IPublicDeleteMediaQuery>

Promise object representing the requestId.

Summary

Delete specified media. It wont go to trash.

Example

const result = await client.medias.deleteMedia("media_id");

downloadMedia

downloadMedia(libraryId, mediaId, options?): Promise<IUbstreamHttpResponseStream>

Download a media. If you request low resolution or plain text, the resources might not be ready to be downloaded. To prevent this call prepareDownloadForMedia first and wait for the request completion by polling on getRequestStatus.

Parameters

Name Type Description
libraryId string The uuid of the targeted library.
mediaId string The uuid of the targeted media.
options? IPublicDownloadOptions Options of the download.

Returns

Promise<IUbstreamHttpResponseStream>

Promise object representing a readable stream, the content-type and the name of the file downloaded.

Summary

Download a media : this method can be used to download one or several variants of the media.

Example

const response = await client.medias.downloadMedia(
  "library_id",
  "media_id",
  {
      quality: PublicDownloadQuality.ORIGINAL,
      language: "en",
      multiLang: false,
      includesMetadata: false,
      metadataFormat: PublicDownloadMetadataFormat.JSON,
      metadataStrategy: PublicDownloadMetadataStrategy.BY_FILE,
  },
);
// Use the readable stream to retrieve the resource.
const writer = fs.createWriteStream(`./${response.filename}`);
await new Promise(((resolve, reject) => {
  writer.on('error', (e) => {
      reject(e);
  })
  writer.on('close', () => {
      resolve(undefined);
  })
  response.stream.pipe(writer);
}));

getMediaUploadStatus

getMediaUploadStatus(mediaId): Promise<IPublicMediaUploadStatus>

Parameters

Name Type Description
mediaId string The uuid of the targeted media.

Returns

Promise<IPublicMediaUploadStatus>

Promise object representing the media upload status.

Summary

After uploading a media, this method can be used to inspect the media upload status (completed or pending)

Example

const status = await client.medias.getMediaUploadStatus("media_id");

listCollectionsOfMedia

listCollectionsOfMedia(libraryId, mediaId): Promise<IPublicLibraryCollectionQuery>

Parameters

Name Type Description
libraryId string The uuid of the targeted library.
mediaId string The uuid of the targeted media.

Returns

Promise<IPublicLibraryCollectionQuery>

Promise object representing all collections where the media is linked.

Summary

Get all the collections where a media is linked.

Example

const result = await client.medias.listCollectionsOfMedia("library_id", "media_id");
const collections = result.$resources;

prepareDownloadForMedia

prepareDownloadForMedia(libraryId, mediaId, options?): Promise<IPublicHttpResponseDataWithRequestId>

Parameters

Name Type Description
libraryId string The uuid of the targeted library.
mediaId string The uuid of the targeted media.
options? IPublicDownloadOptions Options of the download.

Returns

Promise<IPublicHttpResponseDataWithRequestId>

Promise object containing the request ID to use to check the request completion.

Summary

Prepare the download of a media. The missing resources will be generated.

Example

const downloadOptions = {
      quality: PublicDownloadQuality.LOWER,
      language: "en",
      multiLang: false,
      includesMetadata: false,
      metadataFormat: PublicDownloadMetadataFormat.JSON,
      metadataStrategy: PublicDownloadMetadataStrategy.BY_FILE,
};
const prepareResponse = await client.medias.prepareDownloadForMedia(
  "library_id",
  "media_id",
  downloadOptions,
);

// Wait for the request completion here by polling on getRequestStatus:
// await client.requests.getRequestStatus(prepareResponse.requestId)
...

// start the download
const response = await client.medias.downloadMedia (
     "library_id",
     "media_id",
     downloadOptions,
);

publish

publish(mediaId): Promise<IPublicPublishMediaQuery>

Parameters

Name Type Description
mediaId string The uuid of the targeted media.

Returns

Promise<IPublicPublishMediaQuery>

Promise object representing the requestId.

Summary

Publish a media.

Example

const result = await client.medias.publish("media_id");

uploadMedia

uploadMedia(libraryId, collectionId, formData, _options?): Promise<IPublicMediaDocumentUploadResultDataWithRequestId>

Parameters

Name Type Description
libraryId string The uuid of the targeted library.
collectionId string The uuid of the target collection.
formData IFormData The form data containing the file to upload.
_options? string | IPublicCreateMediaOptions -

Returns

Promise<IPublicMediaDocumentUploadResultDataWithRequestId>

Promise object representing the uploaded media, the requestId and the diagnoses of the operation.

Summary

Upload a media in the specified collection.

Example

const file = typeof input === 'string' ? fs.createReadStream(input) : input;
const formData = new FormData(); // https://www.npmjs.com/package/form-data
formData.append('file', file);
const mediaUploaded = await client.medias.uploadMedia("library_id", "collection_id", formData);