Issue #769Opened January 17, 2018by gordon-matt0 reactions

Need further info to create backend for Asset Manager

Question

I'm trying to figure out how to write a backend (in ASP.NET Core) for the Asset Manager. I've looked at a few of the Wiki pages, but still a bit confused. What I'd really like is info about how to show existing assets, upload new ones, delete existing ones, etc. I did see that I can upload by using an upload endpoint as follows:

assetManager: {
    ...
    // Upload endpoint, set `false` to disable upload, default `false`
    upload: 'https://endpoint/upload/assets',

    // The name used in POST to pass uploaded files, default: `'files'`
    uploadName: 'files',
    ...
},

However, that's only for upload. What about delete and load all (to initialize first time)? I was hoping for something like this:

UPLOAD

Parameter: upload Example: upload: 'https://my-site/assets/upload' (HTTP POST) RESPONSE:

{
    success: true/false,
    message: 'Some message here'
}

LIST ALL

Parameter: list Example: list: 'https://my-site/assets/list' (HTTP GET) RESPONSE:

[{
    src: 'http://img.jpg',
    //type: 'image',  //image is default
    height: 300,
    width: 200,
},{
    src: 'http://img2.jpg',
},{
    src: 'http://img3.jpg',
}]

DELETE

Parameter: delete Example: delete: 'https://my-site/assets/delete/{name}' (HTTP DELETE) RESPONSE:

{
    success: true/false,
    message: 'Some message here'
}

Can you please help me understand how to do this? I can't find documentation for the above.. except for upload, but I haven't tried that yet.

Answers (3)

artfJanuary 17, 20180 reactions

Hi @gordon-matt, you manage assets with Asset API and its events, the remote part is up to you

// Init the editor with assets
const editor = grapesjs.init({
	// ...
	assetManager: {
		assets: [
			'https://.../image.png',
			{ src: 'https://...', name: 'Image Title' },
			// ...
		],
		// ...
	}
});

// or even later with Asset's API
const assets = await fetchUsersAssets(); // ['http://...', { ... }]
editor.AssetManager.add(assets);

// For the delete, you can make use of events
editor.on('block:remove', asset => {
	const uuid = asset.get('id') // <- you can pass to assets any custom property
	removeAsset(uuid);
} )
gordon-mattJanuary 17, 20180 reactions

OK I think I see how it works. I'll give that a try, thanks.

lock[bot]September 18, 20190 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.