API
File reading
This pertains to accessing and retrieving data from the uploaded files.
files()
Get all files.
import { useRoqClient } from "/lib/roq"
const allFiles = async () => {
const allFiles = await roqClient.roqPlatform.files()
return allFiles
}
Parameter | Type | Description |
---|---|---|
filter:entityName | object | Name of the object. This could be the name of the table in your database, e.g. "contract". Read FileFilterArgType (opens in a new tab) for more information about file filter |
filter:entityReferences | object | References (or IDs) of the related objects from your database. Read FileFilterArgType (opens in a new tab) for more information about file filter |
filter:fileCategory | object | Filter file by categories. Read FileFilterArgType (opens in a new tab) for more information about file filter |
withFileCategory | boolean | Include file categories |
withCreatedByUser | boolean | Include user data that created the file |
withFileAssociations | boolean | Include file associations |
file()
Get file with specific file ID.
The file()
API also provides information on the file category, its creator, and associations.
import { useRoqClient } from "/lib/roq"
const myfile = async () => {
const myfile = await roqClient.roqPlatform.file({
id: "e54b7785-f7c0-41cc-bfbe-06dbd1645ed9",
withFileCategory: true,
withCreatedByUser: true,
withFileAssociations: true
})
}
Parameter | Type | Description |
---|---|---|
id | UUID | The file ID |
withFileCategory | boolean | Include file category |
withCreatedByUser | boolean | The user that create the file |
withFileAssociations | boolean | Include file associations |
File updating
updateFile()
You can use the updateFile()
API to rename the uploaded files.
import { useRoqClient } from "lib/roq"
const roqClient = useRoqClient()
const updateResult =async () => {
return await roqClient.roqPlatform.updateFile({
id: "97eeb4da-d402-4a89-b034-bcb277b9e65c",
updateFileDto: {
name: "screenshot.png"
}
})
}
Parameter | Type | Description |
---|---|---|
id | UUID | The file ID to be updated |
updateFileDto :name | string | New filename |
updateFileStatus()
The updateFileStatus()
API is a method to set the upload file status. The use case of this API is, for example, you upload a file without using UI Component, and after the file upload is completed, you need to set the upload file status manually.
Five status files are currently available: cancelled
, error
, processing
, ready
, and upload_pending
.
import { useRoqClient } from "lib/roq"
const roqClient = useRoqClient()
const upfileStatus =async () => {
return await roqClient.roqPlatform.updateFileStatus({
id: "97eeb4da-d402-4a89-b034-bcb277b9e65c",
status: FileStatusEnum.Cancelled
})
}
Parameter | Type | Description |
---|---|---|
id | UUID | The file ID to be updated |
status | string | The file status. Look for FileStatusEnum (opens in a new tab) for the details |
File deletion
deleteFiles()
To delete one or multiple files, use the deleteFiles()
API. See this link (opens in a new tab) for the API documentation.
import { useRoqClient } from "lib/roq"
const roqClient = useRoqClient()
const delFiles =async () => {
return await roqClient.asSuperAdmin().deleteFiles({
filter: {
id: {
equalTo: "76dada4e-4f07-456b-90e7-a43099f07052"
}
}
})
}
To delete multiple files, utilize the valueIn
filter option.
{
filter: {
id: {
valueIn: ["file_id_1", "file_id_2"]
}
}
}
Parameter | Type | Description |
---|---|---|
filter:id | object | The IDs of files to delete can be filtered using equalTo for a single file or valueIn for multiple file IDs. |
File categories
File categories can be managed via API or ROQ Console.
Using the fileCategories()
and fileCategory()
APIs from the ROQ Platform, we can retrieve a list of all registered file categories and their details, respectively. These APIs can be easily used on the client-side via front-end SDK.
fileCategories()
Get all file categories.
import { useRoqClient } from "/lib/roq"
const doReadCategories = async () => {
const allCategories = await roqClient.roqPlatform.fileCategories({})
return allCategories
}
fileCategory()
Get file category details.
import { useRoqClient } from "/lib/roq"
const categoryDetails = async () => {
const categoryDetail = await roqClient.roqPlatform.fileCategory({
id: "ff8143f2-cd89-41e9-af16-999c9b9da9b8",
withFileCategoryContentGroups: true
})
return categoryDetail
}
File visibility
A file can be either public or private. Public means that there is a permanent URL that anyone can use, while private files can only be accessed by users who are allowed to do so. The visibility of a file can be changed in ROQ Console or API using the makeFilePrivate()
and makeFilePublic()
. These APIs also can be easily used on the client-side via front-end SDK.
makeFilePublic()
Enable public access to a file.
import { useRoqClient } from "lib/roq"
const roqClient = useRoqClient()
const filePublic =async () => {
return await roqClient.roqPlatform.makeFilePublic({
id: 'fileId'
});
}
makeFilePrivate()
Hide a file from public access.
import { useRoqClient } from "lib/roq"
const roqClient = useRoqClient()
cons private =async () => {
return await roqClient.roqPlatform.makeFilePrivate({
id: 'fileId'
})
}