Object Storage

📘

Required module

Required modules: App engine - Cloud Functions, App engine - UI Components and File Storage. Check your modules at Admin > Licenses. To obtain these modules, contact your IXON account manager or IXON distributor.

Object Storage provides a way to store unstructured data in the IXON Cloud. Examples of unstructured data are text files, images, or CAD drawings. Document Store is recommended for storing structured data. Files are stored on per app. This means that apps can't access each other's files.

Basic app implementation

An app using Object Storage consists of a UI Component and a Cloud Function. The UI Component is used to manage files and the Cloud Function is used to authorize file operations. If an app hasn’t implemented a Cloud Function, all Object Storage calls will be denied.

The ObjectStorageClient is a service that allows objects to be retrieved and manipulated simply and efficiently. You can create a client instance using the createObjectStorageClient() method on the component context.

Cloud Function Hooks

Authorization works based on paths. For security reasons, object access is provided via a Cloud Function. The platform has no opinion on who should or shouldn't be able to access files; this is up to the developer. If the request to your Cloud Function fails for any reason or the response doesn’t meet the requirements, access will be denied. The hooks must be implemented in ayayot/objectstorage_v1.py and the methods must implement the interface as described in the examples below.

All examples below will allow any user to do the actions. If you don't want to allow an action for certain users, you can return None to disallow the action.

Retrieving object list

Object Storage allows you to retrieve all objects in an app. It is not possible to retrieve a single file, you'll need to filter the result. Note that this is about metadata, not the object itself.

objectStorageClient = context.createObjectStorageClient();

const list = await objectStorageClient.getList();
const objects = list.entries;
from ixoncdkingress.function.context import FunctionContext, FunctionResource
from ixoncdkingress.function.objectstorage.types import ResourceType, PathMapping, ListPathResponse


def _request_for(
    context: FunctionContext,
) -> tuple[FunctionResource, ResourceType] | None:
    """
    Detects the target resource of the request, preferring assets to agents.
    Will also return the type of the resource.
    """
    # A company is required in all cases
    if not context.company:
        return None

    target = context.agent
    typ = ResourceType.AGENT

    if context.asset:
        target = context.asset
        typ = ResourceType.ASSET

    if not target:
        return None

    return target, typ

@FunctionContext.expose
def authorize_list(context: FunctionContext) -> ListPathResponse | None:
    """
    Method to validate if and where the caller is allowed
    to get the object list from the object storage.
    """
    if (target_typ := _request_for(context)) is None:
        return None

    target, typ = target_typ
    return ListPathResponse(
        result="success",
        data=list(PathMapping(publicId=target.public_id, type=typ, path="")),
    )

Download a blob

An object can be downloaded as a Blob via getBlob.

objectStorageClient = context.createObjectStorageClient();

const list = await objectStorageClient.getList();
const objectMeta = list.objects[0];

// Get the blob
const blob = await objectStorageClient.getBlob(objectMeta);

// Provide the file to the user
context.saveAsFile(blob, meta.tags.name);
from ixoncdkingress.function.context import FunctionContext
from ixoncdkingress.function.objectstorage.types import PathData, PathResponse

@FunctionContext.expose
def authorize_download(context: FunctionContext) -> PathResponse | None:
    """
    Method to validate if and where the caller is allowed
    to download a blob from the object storage.
    """
    return PathResponse(
        result='success',
        data=PathData(
            path='',
        ),
    )

Delete an object

objectStorageClient = context.createObjectStorageClient();

const list = await objectStorageClient.getList();
const objectMeta = list.objects[0];

await objectStorageClient.delete(objectMeta);
from ixoncdkingress.function.context import FunctionContext
from ixoncdkingress.function.objectstorage.types import PathData, PathResponse

@FunctionContext.expose
def authorize_delete(context: FunctionContext) -> PathResponse | None:
    """
    Method to validate if and where the caller is allowed
    to delete a blob from the object storage.
    """
    return PathResponse(
        result='success',
        data=PathData(
            path='',
        ),
    )

Upload an object

Files can be uploaded as a Blob.

objectStorageClient = context.createObjectStorageClient();

const file = new Blob();

const objectMeta = await objectStorageClient.store(file, {
    tags: {
      	name: filename,
    },
});
from ixoncdkingress.function.context import FunctionContext
from ixoncdkingress.function.objectstorage.types import PathData, PathResponse

@FunctionContext.expose
def authorize_upload(context: FunctionContext) -> PathResponse | None:
    """
    Method to validate if and where the caller is allowed
    to upload a blob to the object storage.
    """
    return PathResponse(
        result='success',
        data=PathData(
            path='',
        ),
    )