thanhtunguet / grapesjs-react

A React wrapper for GrapesJS library
https://thanhtunguet.github.io/grapesjs-react
194 stars 58 forks source link

Save Data to Database. #14

Closed bhavinshahcin7 closed 4 years ago

bhavinshahcin7 commented 5 years ago

Hello, I would like to save the HTML and CSS, both into database. How I can do that? Apart from that I am not able to drag and drop or upload an image into editor.

Any help would be great. Thank You.

thanhtunguet commented 5 years ago

Hello, According to the official docs of GrapesJS (https://grapesjs.com/docs/modules/Storage.html#basic-configuration). You can pass a storeManager configuration to the editor like below:

const  storageManager = {
    type: 'remote',
    stepsBeforeSave: 3,
    urlStore: 'http://endpoint/store-template/some-id-123',
    urlLoad: 'http://endpoint/load-template/some-id-123',
    // For custom parameters/headers on requests
    params: { _some_token: '....' },
    headers: { Authorization: 'Basic ...' },
  };

You can pass your API URL to store the template using urlStore and urlLoad property. Then, you initiate your editor and pass the storeManager configuration as a prop

bhavinshahcin7 commented 5 years ago

Thank you for your reply. I am using grapesjs-react npm plugin. How can I use StoreManager in that ?

Thank You.

thanhtunguet commented 5 years ago

Hi, See my example below:

image

thanhtunguet commented 5 years ago

Sorry, you need to specify storage type as remote:

image