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
| Property | Type | Description |
|---|---|---|
| createdAt | string | The date the asset was created |
| fileLink | string | The link to the asset file |
| key | string | The key of the asset |
| mimeType | string | The mime type of the asset |
| name | string | The name of the asset |
| price | number | The price to use this asset |
| public | boolean | Whether the asset is public |
| type | AssetType | The type of the asset |
AssetType
| Value | Description |
|---|---|
| ColorProfile | An ICC color profile |
| Font | Font |
| Frame | An SVG that supports inserting an image. See Frames |
| Illustration | An SVG |
| Image | An image |
| Material | A material object |
| Model | A 3D model. Currently only GLB is supported |
| Video | A video |