Skip to content

Manage assets on your data source

For use with Netlify Visual Editor only.

When a user uploads assets using the visual editor, Netlify will call the create function that you define with connector.assets() on your connector.

With this API, you need to specify how to upload assets to your data source. Note that you don’t need to define separate logic to get assets because assets are included in data syncs.

For details on what parameters the function has access to, refer to the connector.assets() reference doc.

For example:

connector.assets({
create: async ({ base64, fileName, mimeType, state }) => {
if (base64 === undefined || base64.trim() === "") {
throw new Error("Asset cannot be empty");
}
const cmsAssetData = await state.cmsApiClient.uploadAsset({
base64,
fileName,
mimeType,
});
if (!createdAsset) {
throw new Error(`Failed to create asset`);
}
const { id, url, width, height, createdAt, updatedAt, title } =
createdAsset;
// returning the asset will save it in the visual editor
return {
id,
title,
url,
_status: status,
_createdAt: new Date(createdAt),
_updatedAt: new Date(updatedAt),
width,
height,
};
},
});

Got it!

Your feedback helps us improve our docs.