Code Monkey home page Code Monkey logo

Comments (4)

brijeshb42 avatar brijeshb42 commented on May 27, 2024

Src can have any valid value of an image URL, http/https/data. It should work just fine. At what step is the error occurring? After the image URL is successfully generated?

from medium-draft.

paridin avatar paridin commented on May 27, 2024

The error occurs on setEditorStatus some errores I got 'data is not defined or set unknown key data (if I set directly the url)'

screen shot 2016-12-02 at 3 16 39 am

from medium-draft.

brijeshb42 avatar brijeshb42 commented on May 27, 2024

You should try calling withData(response.data) instead of withData(response)

from medium-draft.

paridin avatar paridin commented on May 27, 2024

Thanks for your help, I saw the bug, I was trying to pass the state to the component so it don't have reference of data object, that's why always I got the error, to reproduce it was looks like

<MyEditor
         editorState={this.state.editorState} onChange={this.onChange} />

and my editor was look like

class MyEditor extends React.Component {
  constructor(props) {
    super(props);
    this.sideButtons = [{
      title: 'Image',
      component: CustomImageSideButton,
    }];
    this.state = {
      editorState:  this.props.editorState || createEditorState(), 
    // here is the bug, I'm interpreting that the context of data is on the parent, 
    // so it returns error _Uncaught Error: Cannot set unknown key "data" on ContentBlock_ 
    // when I type and press enter or when I try to upload the image, 
    // Thats why I don't get the image displayed 
    // To fix it, I removed this this.props.editorState || and it works
    };


    this.onChange = (editorState) => {
      this.setState({ editorState });
    };
  }
  ...
}

to references for people with same issue, my onChange function looks like

  onChange(e) {
    const file = e.target.files[0];
    if (file.type.indexOf('image/') === 0) {
      api
      .get(`/getSignedUrl?folder=news&filename=${file.name}&filetype=${file.type}`)
      .then(response => {
        const signedUrl = response.data.url
        const options = {
          headers: {
            'Content-Type': file.type
          }
        }
        // put to aws
        return axios.put(signedUrl, file, options)

      })
      .then(response => {
        // second step save the data to our database
         this.props.setEditorState(addNewBlock(
           this.props.getEditorState(),
             Block.IMAGE, {
               src: response.request.responseURL.split("?")[0],
             }
           ));
      })
      .catch(e => console.log('Error Uploading in blog', e))
    }
    this.props.close();
  }

so I changes a little bit my called to MyEditor

<MyEditor ref="myeditor" />

and when i need retrieve their content I use the reference

this.refs.myeditor.state.editorState.getCurrentContent()

from medium-draft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.