Skip to main content
Version: v4.6

IafFile

Use the IafFile API to manage file items, file versions, file containers, and named file collections on the platform.

addReqDescriptorToFileItem#

Create relationships between your FileItem and FileItem objects in another FileContainer.

ParameterRequiredTypeDescription
relatedCollYesFileContainerPass the FileContainer object that contains the file items you want to relate your file to. In the object, add an "_id" property and value.
relatedToItemsYesArray<FileItem>Pass an array of related items that you want to be the child related items of your file.
containerYesFileContainerPass the FileContainer object that contains your file. In the object, add an "_id" property and value.
fileItemYesFileItemPass your file as a FileItem object.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

String - 204 response

Examples
let relatedToItems = groupedFiles;
await IafFile.addReqDescriptorToFileItem(relatedColl, relatedToItems, container, fileItem);

cancelResumableFileUpload#

Aborts or cancels a resumable file upload.

ParameterRequiredTypeDescription
containerYesFileContainerFor the container that contains the file, pass a FileContainer object with an "_id" property and value.
fileYesFilePass a File object with an "_id" property and value.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

Promise<void> -

Examples
await cancelResumableFileUpload(currentContainer, uploadedFile, ctx);

createContainer#

Creates a root FileContainer in the File Service with the option to add a FileContainer as a subfolder.

ParameterRequiredTypeDescription
parentContainerYesFileContainerPass a FileContainer object with properties to define your parent folder.
containerInfoNoFileContainerPass a FileContainer object with properties to define your child folder.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileContainer - Created FileContainer

Examples
// Create root containerconst rootContainer = await IafFile.createContainer(  { _namespaces: project._namespaces },  undefined,  ctx);

//Define child containerconst containerInfo = {  _name: "Project A Model documents",  _description: "Project A Model documents",  _shortName: "projAModel",  _userType: "model_docs",};
//Create root container with child containerconst rootContainerWithChild = await IafFile.createContainer(  rootContainer,   containerInfo,   ctx);

createFileItem#

Creates a FileItem class object.

ParameterRequiredTypeDescription
containerYesFileContainerFor the container that contains the file, pass an existing FileContainer object.
fileYesFileItemPass your defined FileItem object.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileItem - The created FileItem object

Examples
const fileData = {  _description: "test_file"};
const testFileItem = await createFileItem(container, fileData, ctx);

createFileItemFromFile#

Creates a FileItem for a file in the File Service.

ParameterRequiredTypeDescription
containerYesFileContainerFor the container that contains the file, pass a FileContainer object with an "_id" property and value.
fileObjYesFilePass a File object with the properties and values you want to define the file item.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileItem - The created FileItem object

Examples
let fileData = {  _name: "file_name",  _type: "file",  _namespaces: ["1_pzOxaMwR"]};
await createFileItemFromFile(container, fileData, ctx);

deleteFileItem#

Deletes a FileItem.

ParameterRequiredTypeDescription
containerYesFileContainerFor the container that contains the file, pass a FileContainer object with an "_id" property and value.
fileItemYesFileItemPass a FileItem object with an "_id" property and value.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

Promise<{itemResult}> -

Examples
await IafFile.deleteFileItem(container, file, ctx);

deleteFileVersion#

Deletes a FileItem version.

ParameterRequiredTypeDescription
containerYesFileContainerPass a container or folder as a FileContainer object.
fileItemYesFileItemPass a FileItem object.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

Promise<void> -

Examples
await IafFileSvc.deleteFileVersion( container, fileItemVersion);

getChildContainers#

Gets the child containers of a FileContainer object you pass.

ParameterRequiredTypeDescription
currentContainerYesFileContainerPass your FileContainer object with an "_id" property and value.
filtersYesundefined
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
optionsNoNamedUserItemCriteriaOptionsPass a NamedUserItemCriteriaOptions object with your response options, such as projection, sort, page size and offset options.
PropertyTypeDescription
filtersUNKNOWN: OptionalTypeTo filter the response, pass a simple query object.
Returns

(Array<FileContainer> | Page<FileContainer>) - Returns an array of the child FileContainer objects. If you set options.pagedRes to true, a Page object with your response returns.

Examples
let childContainers = await IafFile.getChildContainers(  currentContainer,  undefined,  ctx,  undefined);

getContainer#

Gets a FileContainer class object when you pass its id.

ParameterRequiredTypeDescription
idYesStringThe FileContainer's id
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileContainer - The FileContainer object

Examples
const container = await getContainer(containerId);

getContainerPermissions#

Gets a User or UserGroup class object's permissions for a FileContainer.

ParameterRequiredTypeDescription
permUserYesundefined
containerYesFileContainerThe container or folder as a FileContainer object with an "_id" property and value.
ctxYesCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
userYesPermissionUserPass a PermissionUser object for a user or usergroup or permission profile.
Returns

PermissionOperation - A PermissionOperation object with Boolean values for each permission type.

Examples
const permUser = {  _id: user._id,   _type: "user"};
let userPermissions = await getContainerPermissions(permUser, currentContainer);

getContainers#

Gets a project's FileContainer class objects.

ParameterRequiredTypeDescription
nsProviderYesProjectThe Project object
filtersYesJSONTo filter the response, pass a simple query object.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
optionsYesNamedUserItemCriteriaOptionsPass a NamedUserItemCriteriaOptions object with your response options, such as projection, sort, page size and offset options.
Returns

any - Array | Page containers - Returns an array of the project's containers. If you set options.pagedRes to true, a Page object with your response returns.

Examples
let containers = await IafFile.getContainers(  project,   { _name: "Related Files" },   context);

getFileItem#

Gets a FileItem from a file collection.

ParameterRequiredTypeDescription
containerYesFileContainerFor the container that contains the file, pass a FileContainer object with an "_id" property and value.
fileItemYesFileItemPass a FileItem object with an "_id" property and value.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileItem - FileItem

Examples
const fileItem = await IafFile.getFileItem(  container,  { _id: fileId },  ctx);

getFileItems#

Gets file items in a container or folder.

ParameterRequiredTypeDescription
containerYesFileContainerPass a FileContainer object with an "_id" property and value.
filtersYesJSONTo filter your response, pass a simple query object.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
optionsYesRelatedItemCriteriaOptionsPass a RelatedItemCriteriaOptions object with your response options, such as projection, sort, and page size and offset options.
Returns

(Array<FileItem> | Page<FileItem>) - Returns an array of the container's file items. If you set options.pagedRes to true, a Page object with your response returns.

Examples
const container = await IafFile.getRootContainer(project, ctx);const files = await IafFile.getFileItems(container, undefined, ctx);

getFileVerisons#

ParameterRequiredTypeDescription
fileIdYesStringfile id
ctxYesCtxcontext
Returns

Page<FileVersion> - file versions

Examples
let fileVersion = await IafFile.getFileVerisons(  file_id,  ctx);

getItems#

Gets FileItem objects in a FileContainer.

ParameterRequiredTypeDescription
containerYesFileContainerFor the current container, pass a FileContainer object with an "_id" property and value.
filtersYesJSONTo filter your response, pass a simple query object.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
optionsYesRelatedItemCriteriaOptionsPass a RelatedItemCriteriaOptions object with your response options, such as projection, sort, and page size and offset options.
Returns

(Array<FileItem> | Page<FileItem>) - Array or Page of FileItem objects - Returns an array of the container's file items. If you set options.pagedRes to true, a Page object with your response returns.

Examples
const options = {  page: {    _pageSize: 50,    _offset: 100  },  project: {    _metadata: 0  },  sort: {    serial_no: 1  }};
const fileItems = getItems(currentContainer, undefined, ctx, options);

getRootContainer#

Get's a project's root FileContainer.

ParameterRequiredTypeDescription
nsProviderYesProjectThe Project object
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileContainer - The project's root FileContainer

Examples
const { project, ctx } = await common.getCurrentPojectInfo();console.log("fetched project", project);const rootContainer  = await IafFile.getRootContainer(project, ctx);

intactFileVersions#

Keeps a FileItem class object's versions up-to-date.

ParameterRequiredTypeDescription
containerYesFileContainerFor the container that contains the file, pass a FileContainer object with an "_id" property and value.
fileItemYesFileItemPass the existing FileItem object.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

Promise<void> -

Examples
await intactFileVersions(container, fileItem, ctx);

RootContainerName#

setContainerPermissions#

Set permissions for a FileContainer and its folder

ParameterRequiredTypeDescription
containerYesFileContainerFileContainer class object
permUserYesundefined
operationsYesPermissionOperationPermissionOperation class object
ctxYesCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage
userYesPermissionUserPermissionUser class object with either a user id or user group id and their respective types
Returns

JSON - returns {containerPerm: PermissionObject, folderPerm: PermissionObject}

updateContainer#

Updates a FileContainer class object's properties and values.

ParameterRequiredTypeDescription
containerYesFileContainerPass a FileContainer object with an "_id" property and value and the properties and values you want to update.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileContainer - The updated FileContainer object

Examples
// Renaming container let container = await IafFile.getContainer(container, undefined); container._name = newName;
 await IafFile.updateContainer(container, ctx);

updateFileItem#

Updates a FileItem class object.

ParameterRequiredTypeDescription
containerYesFileContainerFor the container that contains the file, pass a FileContainer object with an "_id" property and value.
fileItemYesFileItemPass a FileItem object with an "_id" property and value and the properties and values you want to update.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileItem - Returns the updated FileItem object

Examples
if (item.fileType === "file") {  item.file.name = newName;  await IafFile.updateFileItem(container, item.file, ctx);}

uploadFile#

Uploads a file as a FileItem to a FileContainer.

ParameterRequiredTypeDescription
containerYesFileContainerPass a FileContainer object with an "_id" property and value.
fileYes(File | ReadStream)Pass either a File or ReadStream object.
tagsNoArray<String>Pass any metadata tags you want to add to the file in an array.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
optionsNoFileOptionsPass a FileOptions object with your file options as properties, such as "headers", and "filename".
Returns

FileItem - The created FileItem object

Examples
let file = e.target.files[0];if (file !== undefined) {  let { project, ctx } = await common.getCurrentPojectInfo();
  let container = await IafFile.getContainer(    this.state.selectedId,    undefined  );  let status = await IafFile.uploadFile(container, file, undefined, ctx);}

uploadFileResumable#

Uploads a file that resumes after upload interruptions. You can invoke this method later to resume the file upload from where the upload stopped.

ParameterRequiredTypeDescription
containerYesFileContainerPass a FileContainer object with an "_id" property and value.
fileYes(File | ReadStream)Pass either a File or ReadStream object. For a ReadStream object, specify the filename in the uploadProps parameter.
uploadPropsYesResuambleFileUploadPropsPass a ResuambleFileUploadProps object to add a filename, tags, and callback functions for success, progress and failure.
ctxNoCtxContext storage that contains data, such as authorization token requirements, namespaces, or session storage.
Returns

FileItem - The created FileItem

Examples
let file = fs.createReadStream(filePath);let uploadProps = {filename: 'projectAModel.bimpk', tags: ['model']};
uploadProps.onComplete = (fileItem) =>  console.log('upload success');
uploadProps.onProgress = (bytesUploaded, bytesTotal) => { let percentage = (bytesUploaded / bytesTotal * 100).toFixed(2); console.log(fileInfo._name, bytesUploaded, bytesTotal, percentage + "%");}
uploadProps.onError = (error) => console.log('Failed to upload:',uploadUrl,error)
IafFile.uploadFileResumable(container, file, uploadProps, ctx);
// Upload file with content typelet file = fs.createReadStream(filePath);let uploadProps = {filename: 'Square.svg', tags: ['model']};
uploadProps.onComplete = (fileItem) =>  console.log('upload success');uploadProps.headers = {"Content-Type":"image/svg+xml"}
IafFile.uploadFileResumable(container, file, uploadProps, ctx);