Issue #985Opened March 29, 2018by tomichal1 reactions

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)

artfMarch 31, 20181 reactions

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.

tomichalApril 10, 20180 reactions

@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.

tomichalApril 10, 20180 reactions

... 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:

  1. 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.
  2. Customises the Image asset type of the asset manager such that upon selection of an image in the asset manager, either the src or href attribute of the target component get updated.
  3. 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.

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.