IafFileContainer
Use the IafFileContainer API to manage file containers.
createContainer
Creates a FileContainer class object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | The parent FileContainer id |
| containerInfo | Yes | FileContainer | Pass a FileContainer object with the properties you want to define the your container. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileContainer - The created FileContainer
const containerInfo = {
_name: "elem_warranty_files",
_description: "building_elements_warranty_files",
_shortName: "be_warranties",
_userType: "file_col"
};
const createdContainer = await createContainer(parentContainer._id, containerInfo);
createFileItem
Creates a file item.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | The parent FileContainer's id |
| fileItem | Yes | FileItem | Pass a FileItem object with the properties and values to define your 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 testFileItem = await IafFileContainer.createFileItem(
parentContainer._id,
{_description: "test_file"}
);
createRootContainer
Creates a root FileContainer.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerInfo | Yes | FileContainer | Pass a FileContainer object with the properties you want to define the your root container. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileContainer - The created FileContainer object
const containerInfo = {
_name: "elem_warranty_folder",
};
const rootContainer = await createRootContainer(containerInfo, ctx);
deleteFileItem
Deletes a FileItem.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | The parent FileContainer or folder's id |
| fileItemId | Yes | String | The FileItem's id |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
Promise<{```itemResult```}> -
const deletedFile = await IafFileContainer.deleteFileItem(container._id, fileItem._id);
getChildContainers
Gets the child FileContainer objects of a parent FileContainer.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | The parent FileContainer's id |
| query | No | JSON | To filter your search, pass a simple query object. |
| 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. |
Array<FileContainer> - The child containers that match your query
let childContainers = await IafFile.getChildContainers(
currentFolder._id,
undefined,
ctx,
undefined
);
getContainer
Gets a FileContainer when you pass its id.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | 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 you want
const container = await getContainer(parentContainer._id);
getFileItem
Gets a FileItem from a FileCollection.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | The FileContainer or folder's id |
| fileItemId | Yes | String | The FileItem's id |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileItem - The FileItem object
const file = await IafFileContainer.getFileItem(container._id, fileItem._id);
getFileItems
Gets FileItem objects in a container.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | The FileContainer or folder's id |
| query | Yes | JSON | To filter your response, pass a simple query. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
| options | Yes | RelatedItemCriteriaOptions | optional params such as _pageSize and _offset |
any - Array - Array of FileItem objects
const fileItems = await IafFileContainer.getFileItems(container._id, undefined, ctx, undefined);
updateFileItem
Updates a FileItem with the updated properties and values you pass.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | Pass the FileContainer or folder's id |
| fileItemId | Yes | String | The FileItem's id |
| fileItem | Yes | FileItem | Pass a FileItem object with your updated properties and values. |
| ctx | No | Ctx | Context storage that contains data, such as authorization token requirements, namespaces, or session storage. |
FileItem - The updated FileItem object
const fileItemDesc = {"_description": "updated_test_file"};
const updatedFile = await IafFileContainer.updateFileItem(container._id, file._id, fileItemDesc);
uploadFile
Uploads a file to a FileContainer as a FileItem class object.
| Parameter | Required | Type | Description |
|---|---|---|---|
| containerId | Yes | String | The file container's id. |
| file | Yes | ReadStream | Pass a 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 | Yes | FileOptions | Pass a FileOptions object with your file options as properties, such as "headers", and "filename". |
FileItem - The created FileItem
await IafFileContainer.uploadFile(currentContainer._id, file);