Skip to main content

User Assets

Uploading Assets

The SDK provides a method to upload assets into our system so that they can be used in the workflow editor. This method will return a promise that resolves to the asset object that was created.

import { assetService, AssetType } from '@spiffcommerce/core';

const asset = await assetService.uploadAssetWithProgress(
{
name: 'My Asset', // The name of the asset
blob: blob, // The blob of the asset
},
AssetType.Image, // The type of asset. See AssetType for all available types
(progress: number) => {}, // A callback function that will be called with the progress of the upload,
anonymous, // This should likely always be true.
);

Retrieving Assets

If you have the key to an asset you wish to retrieve you can use the following method to retrieve the asset object. This method will return a promise that resolves to the asset object.

Once you have the asset object you can use the fileLink property to get the link to the asset file.

const asset = await assetService.getLocalOrFromServer(assetKey);
const assetLink = asset.fileLink;
await fetch(assetLink);

Types

Asset

PropertyTypeDescription
createdAtstringThe date the asset was created
fileLinkstringThe link to the asset file
keystringThe key of the asset
mimeTypestringThe mime type of the asset
namestringThe name of the asset
pricenumberThe price to use this asset
publicbooleanWhether the asset is public
typeAssetTypeThe type of the asset

AssetType

ValueDescription
ColorProfileAn ICC color profile
FontFont
FrameAn SVG that supports inserting an image. See Frames
IllustrationAn SVG
ImageAn image
MaterialA material object
ModelA 3D model. Currently only GLB is supported
VideoA video