Skip to main content

Working With Public Links

This guide describes methods for working with public links.

Public links operations#

This chapter describes methods for creating and modifying public links as well as managing collaborators.

Initialization#

import CLFiles from '@cloudike/web_files';
let filesApp;
const options = {  logLevel: 'error' // 'trace' | 'debug' | 'info' | 'warn' | 'error'};
const config = {  authToken: '', // user auth token optional  baseUrl: '', // api base url required  userAgent: '', // user agent name required  wsConfig: { //    sockjs: '', // sockjs url optional    sockjs_for_shares: "", // sockjs for shares url optional      websocket_event_groups: [      "fs",      "photos",      "family"    ], // websocket event groups optional, there are three groups: fs, photos, family    jwt_token: '', // jwt token optional    share_id: '', // share id optional    auth_by_first_message: true // auth by first message optional  }}
try {  filesApp = CLFiles.init(options, config);} catch (error) {  console.log('error', error);}

Shares#

The following code example demonstrates how to obtain the data for a shared instance of a cloud resource according to the provided shareId.

const { publicLinksService, userFSService } = filesApp;const sharedId: string = '<sharedId>';const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };userFSService.getUserId().then((userId) => {  publicLinksService    .getPublicShare(shareId, userId, accessToken, opts)    .then(({ data }) => {      console.log('data', data); //IPublicShareSchema    })    .catch((error) => {    });});

The following code example demonstrates how to create a token to gain access to a cloud resource that has been shared by the owner, using the given shareId.

const { publicLinksService } = filesApp;const sharedId: string = '<sharedId>';const password: string = '<password>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService  .createShareToken(sharedId, password, opts)  .then(({ data }) => {    const { token } = data;  })  .catch((error) => {  });

The following code example demonstrates how to retrieve the data shared by the owner of a cloud resource, using the given shareId.

const { publicLinksService } = filesApp;const sharedId: string = '<sharedId>';const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService  .getSharedWithMeShareById(sharedId, accessToken, opts)  .then(({ data }) => {    const share = data; // IMyShareSchema  })  .catch((error) => {  });

Shared resource operations#

The following code example demonstrates how to get information about a share using itemData, which is of the IFsNodeSchema type.

const { folderOperationsService, publicLinksService } = filesApp;const params: IGetFsNodesSchema = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes; // IFsNodeSchema    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getShare(node, opts);  })  .then(({ data: IMyShareSchema }) => {    const share = data;  })  .catch((error) => {  })

The following code example demonstrates how to create a new share using itemData, which is of IFsNodeSchema type.

const { folderOperationsService, publicLinksService } = filesApp;const params: IGetFsNodesSchema = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes;    const params: ICreateMyShareSchema = { access_type: ShareAccessTypes.ALL };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.createShare(node, params, opts);  })  .then(({ data }) => {    const share = data; // IMyShareSchema  })  .catch((error) => {  });

The following code example demonstrates how to update existing share by itemData, which is of IFsNodeSchema type.

const { folderOperationsService, publicLinksService } = filesApp;const params: ICreateMyShareSchema = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes.filter((item) => item.is_shared);    const params: ICreateMyShareSchema = { access_type: ShareAccessTypes.COLLABORATORS };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.updateShare(node, params, opts);  })  .then(({ data }) => {    const share = data; // IMyShareSchema  })  .catch((error) => {  });

The following code example demonstrates how to delete an existing share using itemData, which is of the IFsNodeSchema type.

const { folderOperationsService, publicLinksService } = filesApp;const params = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes.filter((item) => item.is_shared);    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.deleteShare(node, opts);  })  .catch((error) => {  });

Collaborators#

The following code example demonstrates how to get a list of collaborators for a share.

const { folderOperationsService, publicLinksService } = filesApp;const params = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes.filter((item) => item.is_shared);    const params: IGetEmbeddedSchema = { embedded: true };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getCollaborators(node, params, opts);  })  .then(({ data }) => {    const collaborators = data; // ICollaboratorsSchema  })  .catch((error) => {  });

The following code example demonstrates how to add a new collaborator to a share.

const { folderOperationsService, publicLinksService } = filesApp;const params: IGetFsNodesSchema = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes.filter((item) => item.is_shared);    const params = {      phone_or_email: 'example@test.com',      permission: SharePermissionType.WRITE,    };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.addCollaborator(node, params, opts);  })  .then(() => {  })  .catch((error) => {  });

The following code example demonstrates how to get data of a collaborator.

const { folderOperationsService, publicLinksService } = filesApp;const params: IGetFsNodesSchema = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes.filter((item) => item.is_shared);    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getCollaborator(node, opts);  })  .then(({ data }) => {    const collaborator = data; // ICollaboratorSchema  })  .catch((error) => {  });

The following code example demonstrates how to update the data of a collaborator.

const { folderOperationsService, publicLinksService } = filesApp;const params = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes.filter((item) => item.is_shared);    const params = {      permission: SharePermissionType.READ,    };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.updateCollaborator(node, params, opts);  })  .then(({ data }) => {    const collaborator = data; // ICollaboratorSchema  })  .catch((error) => {  });

The following code example demonstrates how to delete data of a collaborator.

const { folderOperationsService, publicLinksService } = filesApp;const params: IGetFsNodesSchema = { parent_id: '<parent_id>' };folderOperationsService  .getFolderContent(params)  .then(({ data }) => {    const {      _embedded: { nodes },    } = data;    const [node] = nodes.filter((item) => item.is_shared);    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.deleteCollaborator(node, opts);  })  .then(() => {  })  .catch((error) => {  });

Shared with me#

The following code example demonstrates how to retrieve a list of shared root folders.

const { publicLinksService } = filesApp;const params: IGetSharedWithMeFsRootsSchemas = { embedded: true };const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService  .getShareWithMeRoots(params, opts)  .then(({ data }) => {    console.log('data', data); // ISharedWithMeFsRootsSchemas  })  .catch((error) => {  });

The following code example shows how to use the ShareWithMeRootsPaginator to obtain a list of shared root folders.

const { publicLinksService } = filesApp;const pageSize: number = 20;const params: IGetSharedWithMeFsRootsSchemas = { embedded: true };const opts: CustomRequestConfig = { signal: '<AbortSignal>' };const paginator =  publicLinksService.getShareWithMeRootsPaginator(pageSize, params, opts);paginator  .next()  .then(({ data }) => {    console.log('data', data); // ISharedWithMeFsRootsSchemas  })  .catch((error) => {  });

The following code example demonstrates how to obtain the content of the shared folder's root directory.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const params: IGetNotMyFsRootSchema = { embedded: true };const opts: CustomRequestConfig = { signal: '<AbortSignal>' };const accessToken = '<accessToken>';publicLinksService.getNotMyFsRootDir(shareId, params, accessToken, opts)  .then(({ data }) => {    console.log('data', data); // IFsNodesSchema  })  .catch((error) => {  });

The following code example demonstrates the process of obtaining information about the root directory of a shared folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const params: IGetNotMyFsRootSchema = { embedded: true };const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService.getNotMyFsRootNode(shareId, params, accessToken, opts)  .then(({ data }) => {    console.log('data', data); // IFsNodesSchema  })  .catch((error) => {  });

The following code example demonstrates how to retrieve data from the root folder that is shared with the owner using a share ID.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const params: IGetNotMyFsRootSchema = { embedded: true };const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService  .getShareWithMeRootById(shareId, params, accessToken, opts)  .then(({ data }) => {    console.log('data', data); // INotMyFileSchema  })  .catch((error) => {  });

The following code example demonstrates how to delete data that's shared with the owner of the cloud resource, given that the share ID comes with write permission.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService  .deleteSharedWithMe(shareId, accessToken, opts)  .then(() => {  })  .catch((error) => {  });

Not my FS operations#

The following code example demonstrates how to retrieve a list of nodes from a shared root folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        nodes: { href: url },      },    } = data;    return url;  })  .then((url) => {    const params = { embedded: true };    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getNotMyFsNodesByLink(      url,      params,      accessToken,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IFsNodesSchema  });

The following code example demonstrates how to obtain the ShareWithMeRootsPaginator for a list of nodes from a shared root folder.

const { publicLinksService } = filesApp;const shareId = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        nodes: { href: url },      },    } = data;    return url;  })  .then((url) => {    const params: IGetFsNodesSchema = { embedded: true };    const pageSize: number = 20;    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getNodesByLinkPaginator(      url,      pageSize,      params,      accessToken,      opts    );  })  .then((paginator) => {    return paginator.next();  })  .then(({ data }) => {    console.log('data', data); //IFsNodesSchema  });

The following code example demonstrates how to retrieve a node from a shared root folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        node: { href: urlTmpl },      },    } = data;    return urlTmpl;  })  .then((urlTmpl) => {    const nodeId: string = '<nodeId>';    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getNotMyFsNodeByLink(      urlTmpl,      nodeId,      accessToken,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IFsNodeSchema  });

The following code example demonstrates how to create a node for a shared root folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const token: string = '<accessToken>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true }, token)  .then(({ data }) => {    const {      _links: {        nodes: { href: nodesUrl },        ids: { href: idsUrl },      },    } = data;    return { nodesUrl, idsUrl };  })  .then(({ nodesUrl, idsUrl }) => {    const params = { type: 'dir', name: 'test dir' };    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.createNotMyFsNodeByLink(      nodesUrl,      idsUrl,      params,      accessToken,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IFsNodeSchema  });

The following code example demonstrates how to rename a node, move it to another parent folder, or move it to the trash bin from a shared root folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const params: IGetNotMyFsRootSchema = { preview: true };const token: string = '<accessToken>';publicLinksService  .getShareWithMeRootById(shareId, params, token)  .then(({ data }) => {    const {      _links: {        node: { href: urlTmpl },      },    } = data;    return urlTmpl;  })  .then((urlTmpl) => {    const nodeId = '<nodeId>';    const params: IPatchFsNodeSchema = { name: 'new name' };    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.updateNotMyFsNodeByLink(      urlTmpl,      nodeId,      params,      accessToken,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IFsChangedNodeSchema  });

The following code example demonstrates how to completely remove a node from a shared root folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const params: IGetNotMyFsRootSchema = {};publicLinksService  .getShareWithMeRootById(shareId, params)  .then(({ data }) => {    const {      _links: {        node: { href: urlTmpl },      },    } = data;    return urlTmpl;  })  .then((urlTmpl) => {    const nodeId: string = '<nodeId>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.removeNotMyFsNodeByLink(urlTmpl, nodeId, opts);  })  .then(({ data }) => {    console.log('data', data); //IFsChangedNodeSchema  });

The following code example demonstrates how to start copying a directory that is a node of a shared folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const srcNodeId: string = '<srcNodeId>'; //copied dir idconst distNodeId: string = '<distNodeId>'; //distinction dir idlet copyDirTasksUrl: string = '';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        dir_copy_tasks: { href: copyDirTasksUrl },        node: { href: nodeUrlTmpl },      },    } = data;    return Promise.all([      publicLinksService.getNotMyFsNodeByLink(nodeUrlTmpl, srcNodeId),      copyDirTasksUrl,    ]);  })  .then(([srcNode, copyDirTasksUrl]) => {    const {      _links: {        self: { href: srcUrl },      },    } = srcNode;    const distParams: IDestinationParams = {      source: srcUrl,      destination: { parent_id: distNodeId },    };    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.copySharedWithMeDir(      copyDirTasksUrl,      distParams,      accessToken,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IDirCopyTaskSchema  });

The following code example demonstrates the copying of a directory to a personal cloud.

const srcNodeId: string = '<srcNodeId>'; //copied dir idconst parentId: string = '<parentId>'; //parent dir id in personal cloudconst shareId: string = '<shareId>';const params = {  name: '',  unique_name: true,};const checkStatusDelay: number = 500;const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService.folderOperationsService  .copySharedWithMeDirToPersonal(    srcNodeId,    parentId,    shareId,    params,    checkStatusDelay,    accessToken,    opts  )  .then(({ data }) => {    console.log('data', data); //IDirCopyTaskSchema  });

The following code example demonstrates the copying of a root public directory to a personal cloud.

const parentId: string = '<parentId>'; //parent dir id in personal cloudconst shareId: string = '<shareId>';const params = {  name: '',  unique_name: true,};const checkStatusDelay: number = 500;const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService.folderOperationsService  .copySharedWithMeRootDirToPersonal(    parentId,    shareId,    params,    checkStatusDelay,    accessToken,    opts  )  .then(({ data }) => {    console.log('data', data); //IDirCopyTaskSchema  });

The following code example demonstrates how to copy a file, which is a node of a shared folder, by using node links.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const srcNodeId: string = '<srcNodeId>'; //copied file node idconst parentId: string = '<parentId>'; //parent dir idpublicLinksService  .getShareWithMeRootById(shareId)  .then(({ data }) => {    const {      _links: {        nodes: { href: nodesUrl },        node: { href: nodeUrl },        ids: { href: idsUrl },      },    } = data;    const links = { nodesUrl, srcNodeUrlTmpl: nodeUrl, idsUrl };    // if you have to rename a file use extParams    const extParams = { name: 'newAwesomeName' };    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.copySharedWithMeByLinks(      srcNodeId,      parentId,      links,      extParams,      accessToken,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IFsNodeSchema  });

The following code example demonstrates how to copy a file, which is a node of a shared folder, using the share ID.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const srcNodeId: string = '<srcNodeId>'; //copied file node idconst parentId: string = '<parentId>'; //parent dir id// if you have to rename a file use extParamsconst extParams = { name: 'newAwesomeName' };const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService  .copySharedWithMeByShareId(    srcNodeId,    parentId,    shareId,    extParams,    accessToken,    opts  )  .then(({ data }) => {    console.log('data', data); //IFsNodeSchema  });

The following code example demonstrates how to copy a file, which is a node of a shared folder, identified by its share ID, to a personal cloud.

const { publicLinksService } = filesApp;const srcNodeId: string = '<srcNodeId>'; //copied file node idconst parentId: string = '<parentId>'; //parent dir id in personal cloudconst shareId: string = '<shareId>';// if you have to rename a file use extParamsconst extParams = { name: 'newAwesomeName' };const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };publicLinksService  .copySharedWithMeByShareIdToPersonal(    srcNodeId,    parentId,    shareId,    extParams,    accessToken,    opts  )  .then(({ data }) => {    console.log('data', data); //IFsNodeSchema  });

The following code example demonstrates how to retrieve the status of tasks related to copying a directory, in a shared folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        dir_copy_tasks: { href: copyDirTasksUrl },      },    } = data;    return copyDirTasksUrl;  })  .then((copyDirTasksUrl) => {    const params = { embedded: true };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getSharedWithMeCopyDirTasks(      copyDirTasksUrl,      distParams,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IDirCopyTasksSchema  });

The following code example demonstrates how to obtain the CopyDirTasksPaginator for a list of copying folder tasks.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        dir_copy_tasks: { href: copyDirTasksUrl },      },    } = data;    return copyDirTasksUrl;  })  .then((copyDirTasksUrl) => {    const params: IGetDirCopyTasksSchema = { embedded: true };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getSharedWithMeCopyDirTasksPaginator(      copyDirTasksUrl,      pageSize,      params,      opts    );  })  .then((paginator) => {    return paginator.next();  })  .then(({ data }) => {    console.log('data', data); //IDirCopyTasksSchema  });

The following code example demonstrates how to retrieve the object data of a files node.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        file_objects: { href: fileObjectsUrl },      },    } = data;    return fileObjectsUrl;  })  .then((fileObjectsUrl) => {    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getSharedWithMeFileObjects(      fileObjectsUrl    );  })  .then(({ data }) => {    console.log('data', data); //IFileObjectSchema  });

The following code example demonstrates how to create an object from the data of a file node.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        file_objects: { href: fileObjectsUrl },      },    } = data;    return fileObjectsUrl;  })  .then((fileObjectsUrl) => {    const params: ICreateFsFileObject = {};    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.createSharedWithMeFileObject(      fileObjectsUrl,      params,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IFileObjectSchema  });

Download#

The following code example demonstrates how to get the download link for a file.

const nodeId: string = '<nodeId>';const shareId: string = '<shareId>';const accessToken: string = '<accessToken>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };filesApp.publicLinksService  .getDownloadLink(shareId, nodeId, accessToken, opts)  .then((link) => {    console.log('link', link);    link    to    the    file  });

The following code example demonstrates how to get the download link for the file from its content URL.

const contentUrl: string = '<contentUrl>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };filesApp.publicLinksService  .getDownloadLinkByContentUrl(contentUrl, opts)  .then((link) => {    console.log('link', link); // link to the file  });

The following code example demonstrates how to create a zip stream and get a link to download the zip archive.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        nodes_downloads: { href: nodesDownloadsUrl },      },    } = data;    return nodesDownloadsUrl;  })  .then((nodesDownloadsUrl) => {    const nodesIds: string[] = ['nodeId1', 'nodeId1'];    const accessToken: string = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.createSharedWithMeNodesZipStream(      nodesDownloadsUrl,      nodesIds,      accessToken,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IDownloadSchema    const {      _links: {        zip_stream: { href: downloadZipUrl },      },    } = data;    // to start downloading    window.location.assign(downloadZipUrl);  });

Versions#

The following code example demonstrates how to retrieve data for a specific version of a file node that is located within a shared folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const nodeId: string = '<nodeId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        file_versions: { href: fileVersionsUrlTmpl },      },    } = data;    return fileVersionsUrlTmpl;  })  .then((fileVersionsUrlTmpl) => {    const params = { embedded: true };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getSharedWithMeFileVersionsByLink(      fileVersionUrlTmpl,      nodeId,      params,      opts    );  })  .then(({ data }) => {    const {      _embedded: { versions },    } = data;    console.log('versions', versions);  });

The following code example demonstrates how to obtain the paginator for a list of copying folder tasks.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const nodeId: string = '<nodeId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        file_versions: { href: fileVersionsUrlTmpl },      },    } = data;    return fileVersionsUrlTmpl;  })  .then((fileVersionsUrlTmpl) => {    const pageSize: number = 20;    const params: IGetVersionsSchema = { embedded: true };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.getSharedWithMeFileVersionsByLinkPaginator(      fileVersionsUrlTmpl,      pageSize,      params,      opts    );  })  .then((paginator) => {    return paginator.next();  })  .then(({ data }) => {    console.log('data', data); //IVersionsSchema  });

The code snippet exemplified below demonstrates the method to acquire data for a specific version of a file node, which is found within a shared folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        file_version: { href: fileVersionUrlTmpl },      },    } = data;    return fileVersionUrlTmpl;  })  .then((fileVersionUrlTmpl) => {    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    const nodeId: string = '<nodeId>';    const versionId: string = '<versionId>';    return publicLinksService.getSharedWithMeFileVersionByLink(      fileVersionUrlTmpl,      nodeId,      versionId,      opts    );  })  .then(({ data }) => {    console.log('data', data); //IVersionSchema  });

The following code example demonstrates the procedure of deleting data for a specific version of a file node, which is located within a shared folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      _links: {        file_version: { href: fileVersionUrlTmpl },      },    } = data;    return fileVersionUrlTmpl;  })  .then((fileVersionUrlTmpl) => {    const nodeId: string = '<nodeId>';    const versionId: string = '<versionId>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.deleteSharedWithMeNodeVersionByLink(      fileVersionUrlTmpl,      nodeId,      versionId,      opts    );  })  .then(() => {    // version was successfully deleted  });

The following code example demonstrates uploading a new version of a file node to the shared folder.

  const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService.getShareWithMeRootById(shareId)  .then(({ data }) => {    const {      _links: {        ids: { href: idsUrl }      },    } = data;    return idsUrl;  })  .then((idsUrl) => {    const file: IFileObject = '<fileObject>';    const distNodeId: string = '<distNodeId>'; // id of distinction node    const params = { node_id: distNodeId };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    return publicLinksService.uploadNewFileVersion(shareId, idsUrl, file, params, opts);  })  .then((uploadedFiles: IFsNodeSchema[]) => {    console.log('uploadedFiles', uploadedFiles);  });

Upload#

The following code example demonstrates uploading file to the shared folder.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';publicLinksService  .getShareWithMeRootById(shareId)  .then(({ data }) => {    const {      _links: {        ids: { href: idsUrl },      },    } = data;    return idsUrl;  })  .then((idsUrl) => {    const accessToken = '<accessToken>';    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    const file: IFileObject = '<fileObject>';    const params: IUploaderProxyParams = { parent_id: '' };    return publicLinksService.uploadFileItem(      shareId,      idsUrl,      file,      params,      accessToken,      opts    );  })  .then((uploadedFiles: IFsNodeSchema[]) => {    console.log('uploadedFiles', uploadedFiles);  });

The following code example demonstrates uploading files to the shared folder.

  const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const fileList: IFileObject[] = [fileObject1, fileObject2];publicLinksService.getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      ids: { href: idsUrl }    } = data;    return idsUrl;  })  .then((idsUrl) => {    const params: IUploaderProxyParams = { parent_id: '' };    const opts: CustomRequestConfig = { signal: '<AbortSignal>' };    const accessToken: string = '<accessToken>';    return publicLinksService.uploadFileItems(shareId, idsUrl, fileList, params, accessToken, opts);  })  .then((uploadedFiles: IFsNodeSchema[]) => {    console.log('uploadedFiles', uploadedFiles);  });

The following code example demonstrates operations with a list of uploaded files.

const { publicLinksService } = filesApp;const shareId: string = '<shareId>';const fileList: IFileObject[] = ['fileObject1', 'fileObject2'];const params: IUploaderProxyParams = { parent_id: '' };publicLinksService  .getShareWithMeRootById(shareId, { preview: true })  .then(({ data }) => {    const {      ids: { href: idsUrl },    } = data;    return idsUrl;  })  .then(async (idsUrl) => {    const accessToken: string = '<accessToken>';    const uploaderList = await publicLinksService.addToUploadList(      shareId,      idsUrl,      files,      params,      accessToken    );    // to get list updates you need to subscribe to 'update' event    uploaderList.on('update', async ({ list, state }) => {      // get list of files      items = list; // Array<File | UploaderBase>      // state of file list      listState = state; // IUploaderListState      if (!!items && items.length > 0) {        // to remove item from item list        const item = items[0];        await uploaderList.remove(item);        // to restart uploading of any item which haven't been uploaded successfully.        await uploaderList.restart(item);        // to resume uploading of photos        await uploaderList.resume();        // to stop uploading photos        uploaderList.cancel();        // to clear file list        uploaderList.clear();      }    });    // to catch list updates error you need to subscribe to 'error' event    uploaderList.on('error', (error) => {      const uploaderListError = error; // UploaderListError    });  });