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.
| Parameter | Required | Type | Description |
|---|---|---|---|
| relatedColl | Yes | FileContainer | Pass the FileContainer object that contains the file items you want to relate your file to. In the object, add an "_id" property and value. |
| relatedToItems | Yes | Array<FileItem> | Pass an array of related items that you want to be the child related items of your file. |
| container | Yes | FileContainer | Pass the FileContainer object that contains your file. In the object, add an "_id" property and value. |
| fileItem | Yes | FileItem | Pass your file as a FileItem object. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
String - 204 response
let relatedToItems = groupedFiles;
await IafFile.addReqDescriptorToFileItem(relatedColl, relatedToItems, container, fileItem);cancelResumableFileUpload#
Aborts or cancels a resumable file upload.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the container that contains the file, pass a FileContainer object with an "_id" property and value. |
| file | Yes | File | Pass a File object with an "_id" property and value. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
await cancelResumableFileUpload(currentContainer, uploadedFile, ctx);createContainer#
Creates a root FileContainer in the File Service with the option to add a FileContainer as a subfolder.
| Parameter | Required | Type | Description |
|---|---|---|---|
| parentContainer | Yes | FileContainer | Pass a FileContainer object with properties to define your parent folder. |
| containerInfo | No | FileContainer | Pass a FileContainer object with properties to define your child folder. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileContainer - Created FileContainer
// 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.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the container that contains the file, pass an existing FileContainer object. |
| file | Yes | FileItem | Pass your defined FileItem object. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileItem - The created FileItem object
const fileData = { _description: "test_file"};
const testFileItem = await createFileItem(container, fileData, ctx);createFileItemFromFile#
Creates a FileItem for a file in the File Service.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the container that contains the file, pass a FileContainer object with an "_id" property and value. |
| fileObj | Yes | File | Pass a File object with the properties and values you want to define the file item. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileItem - The created FileItem object
let fileData = { _name: "file_name", _type: "file", _namespaces: ["1_pzOxaMwR"]};
await createFileItemFromFile(container, fileData, ctx);deleteFileItem#
Deletes a FileItem.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the container that contains the file, pass a FileContainer object with an "_id" property and value. |
| fileItem | Yes | FileItem | Pass a FileItem object with an "_id" property and value. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
Promise<{itemResult}> -
await IafFile.deleteFileItem(container, file, ctx);deleteFileVersion#
Deletes a FileItem version.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | Pass a container or folder as a FileContainer object. |
| fileItem | Yes | FileItem | Pass a FileItem object. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
await IafFileSvc.deleteFileVersion( container, fileItemVersion);getChildContainers#
Gets the child containers of a FileContainer object you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| currentContainer | Yes | FileContainer | Pass your FileContainer object with an "_id" property and value. |
| filters | Yes | undefined | |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
| options | No | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with your response options, such as projection, sort, page size and offset options. |
| Property | Type | Description |
|---|---|---|
| filters | UNKNOWN: OptionalType | To filter the response, pass a simple query object. |
(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.
let childContainers = await IafFile.getChildContainers( currentContainer, undefined, ctx, undefined);getContainer#
Gets a FileContainer class object when you pass its id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| id | Yes | String | The FileContainer's id |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileContainer - The FileContainer object
const container = await getContainer(containerId);getContainerPermissions#
Gets a User or UserGroup class object's permissions for a FileContainer.
| Parameter | Required | Type | Description |
|---|---|---|---|
| permUser | Yes | undefined | |
| container | Yes | FileContainer | The container or folder as a FileContainer object with an "_id" property and value. |
| ctx | Yes | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
| user | Yes | PermissionUser | Pass a PermissionUser object for a user or usergroup or permission profile. |
PermissionOperation - A PermissionOperation object with Boolean values for each permission type.
const permUser = { _id: user._id, _type: "user"};
let userPermissions = await getContainerPermissions(permUser, currentContainer);getContainers#
Gets a project's FileContainer class objects.
| Parameter | Required | Type | Description |
|---|---|---|---|
| nsProvider | Yes | Project | The Project object |
| filters | Yes | JSON | To filter the response, pass a simple query object. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
| options | Yes | NamedUserItemCriteriaOptions | Pass a NamedUserItemCriteriaOptions object with your response options, such as projection, sort, page size and offset options. |
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.
let containers = await IafFile.getContainers( project, { _name: "Related Files" }, context);getFileItem#
Gets a FileItem from a file collection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the container that contains the file, pass a FileContainer object with an "_id" property and value. |
| fileItem | Yes | FileItem | Pass a FileItem object with an "_id" property and value. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileItem - FileItem
const fileItem = await IafFile.getFileItem( container, { _id: fileId }, ctx);getFileItems#
Gets file items in a container or folder.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | Pass a FileContainer object with an "_id" property and value. |
| filters | Yes | JSON | To filter your response, pass a simple query object. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
| options | Yes | RelatedItemCriteriaOptions | Pass a RelatedItemCriteriaOptions object with your response options, such as projection, sort, and page size and offset options. |
(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.
const container = await IafFile.getRootContainer(project, ctx);const files = await IafFile.getFileItems(container, undefined, ctx);getFileVerisons#
| Parameter | Required | Type | Description |
|---|---|---|---|
| fileId | Yes | String | file id |
| ctx | Yes | Ctx | context |
Page<FileVersion> - file versions
let fileVersion = await IafFile.getFileVerisons( file_id, ctx);getItems#
Gets FileItem objects in a FileContainer.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the current container, pass a FileContainer object with an "_id" property and value. |
| filters | Yes | JSON | To filter your response, pass a simple query object. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
| options | Yes | RelatedItemCriteriaOptions | Pass a RelatedItemCriteriaOptions object with your response options, such as projection, sort, and page size and offset options. |
(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.
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.
| Parameter | Required | Type | Description |
|---|---|---|---|
| nsProvider | Yes | Project | The Project object |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileContainer - The project's root FileContainer
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.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the container that contains the file, pass a FileContainer object with an "_id" property and value. |
| fileItem | Yes | FileItem | Pass the existing FileItem object. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
await intactFileVersions(container, fileItem, ctx);RootContainerName#
setContainerPermissions#
Set permissions for a FileContainer and its folder
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | FileContainer class object |
| permUser | Yes | undefined | |
| operations | Yes | PermissionOperation | PermissionOperation class object |
| ctx | Yes | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage |
| user | Yes | PermissionUser | PermissionUser class object with either a user id or user group id and their respective types |
JSON - returns {containerPerm: PermissionObject, folderPerm: PermissionObject}
updateContainer#
Updates a FileContainer class object's properties and values.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | Pass a FileContainer object with an "_id" property and value and the properties and values you want to update. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileContainer - The updated FileContainer object
// Renaming container let container = await IafFile.getContainer(container, undefined); container._name = newName;
await IafFile.updateContainer(container, ctx);updateFileItem#
Updates a FileItem class object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | For the container that contains the file, pass a FileContainer object with an "_id" property and value. |
| fileItem | Yes | FileItem | Pass a FileItem object with an "_id" property and value and the properties and values you want to update. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileItem - Returns the updated FileItem object
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.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | Pass a FileContainer object with an "_id" property and value. |
| file | Yes | (File | ReadStream) | Pass either a File or ReadStream object. |
| tags | No | Array<String> | Pass any metadata tags you want to add to the file in an array. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
| options | No | FileOptions | Pass a FileOptions object with your file options as properties, such as "headers", and "filename". |
FileItem - The created FileItem object
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.
| Parameter | Required | Type | Description |
|---|---|---|---|
| container | Yes | FileContainer | Pass a FileContainer object with an "_id" property and value. |
| file | Yes | (File | ReadStream) | Pass either a File or ReadStream object. For a ReadStream object, specify the filename in the uploadProps parameter. |
| uploadProps | Yes | ResuambleFileUploadProps | Pass a ResuambleFileUploadProps object to add a filename, tags, and callback functions for success, progress and failure. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileItem - The created FileItem
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);