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)
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);
} )
OK I think I see how it works. I'll give that a try, thanks.
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.
Issue #358
Calling updateScript from the script section of a pluging
Hi guys, I've been stuck for a few hours trying to figure out how to call updateScript from the script section of a custom plugin. So far I...
Issue #1805
Define new Image component
I'm new to GrapesJs and am unable to figure out how to create an image component. For example, I have an img tag and have defined the src ,...
Issue #875
[Question]: Is it possible to customize the editor completely?
I really like GrapesJS functionality but I'm a little disappointed with the lack of options when it comes to the editor, it looks good by i...
Issue #985
Can GrapesJS allow uploading arbitrary file through the built in asset manager?
I looked at the asset manager code as well as the wiki and it seems like despite the docs claiming that the asset manager can handle upload...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.