Can GrapesJS allow uploading arbitrary file through the built in asset manager?
Question
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 uploading arbitrary files (i.e. by adding an arbitrary asset type), the actual asset manager code hardcodes file type image/* on the file input field of the file upload form https://github.com/artf/grapesjs/blob/d5f0ae94dfd801a8c13cc0f6ce33e209f98f1c65/src/asset_manager/view/FileUploader.js#L8
Is this a bug/oversight and indeed the asset manager code needs to be modified/hacked, or am I missing a way to configure the manager to accept the file types matching the default asset types (image only so far?) as well as any arbitrary asset types?
My use case is to hook up the link component with the asset manager such that a user can upload a document file (pdf, doc, xls, ...) and upon doing so the asset manager updates the href attribute of the targeted link component.
Answers (3)
Good question, I think the issue is the OpenAssets command itself that should be renamed in OpenImageAssets (indeed it renders only images types). So, what you can try to do is to create another command (eg. a more generic one or just for documents) and see if the customization works out for you.
If you will see any point of improvement in the process I'll be glad to discuss it.
@artf I created the referenced pull request. I admit my motivation was my specific use case, but hopefully it was coded generically enough to be acceptable in the core editor codebase.
... oh and just to clarify - another chunk of code written alongside this pull request resides in a custom plugin of my project. It's a plugin that essentially does the following:
- Customises the Link DOM component such that upon creating a link via the RTE, the asset manager opens up at which point an arbitrary asset can be uploaded and linked to the newly created link component.
- Customises the Image asset type of the asset manager such that upon selection of an image in the asset manager, either the
srcorhrefattribute of the target component get updated. - Adds an Other asset type to the asset manager. The Other asset type is used alongside the Image asset type if the asset manager is used for the Link DOM component.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #372
Asset Manager not automatically add images to assets after uploading
The JSON response of an upload is like this {"data":["http://url.com/flower.jpg"]} The response event is working.In the response event resp...
Issue #401
Cannot upload images
Hi, while uploading an image through asset manager, I get the following error: Assetmanager configuration at editor init looks like Folder...
Issue #769
Need further info to create backend for Asset Manager
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...
Issue #1226
Specifying tooltips
Hi, I've tried finding information about it in both the code as well as existing issues but either I looked for the wrong information or it...
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.