Проблема с отображением загрузки файла для изображения в Draft JS

Я обновил мою базу данных и таблицу до версии с utf8 до utf8mb4. Но для меня ничего не работает. Затем я попытался обновить тип данных столбца до blob, к счастью, он работал для меня, и данные были сохранены. Даже моя база данных и таблица - это CHARACTER SET utf8 COLLATE utf8_unicode

0
задан Chandrika Joshi 29 March 2019 в 12:22
поделиться

1 ответ

Решил проблему. Я забыл реализовать функцию обратного вызова для загрузки файла. вот рабочий код.

import React, { Component } from 'react';
import logo from './logo.svg';

import { EditorState } from 'draft-js';
import { Editor } from 'react-draft-wysiwyg';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';


class App extends Component {

  constructor(props) {
    super(props);
    this.state = {
      editorState: EditorState.createEmpty(),
      uploadedImages:[]
    };
    this._uploadImageCallBack = this._uploadImageCallBack.bind(this);
  }

  onEditorStateChange: Function = (editorState) => {
    this.setState({
      editorState,
    });
  };


  _uploadImageCallBack(file){
    // long story short, every time we upload an image, we
    // need to save it to the state so we can get it's data
    // later when we decide what to do with it.

   // Make sure you have a uploadImages: [] as your default state
    let uploadedImages = this.state.uploadedImages;

    const imageObject = {
      file: file,
      localSrc: URL.createObjectURL(file),
    }

    uploadedImages.push(imageObject);

    this.setState({uploadedImages: uploadedImages})

    // We need to return a promise with the image src
    // the img src we will use here will be what's needed
    // to preview it in the browser. This will be different than what
    // we will see in the index.md file we generate.
    return new Promise(
      (resolve, reject) => {
        resolve({ data: { link: imageObject.localSrc } });
      }
    );
  }
  render() {
    const { editorState } = this.state;
    return (
      <div className="App">
        <header className="App-header">

         <Editor
  editorState={editorState}
  toolbarClassName="toolbarClassName"
  wrapperClassName="wrapperClassName"
  editorClassName="editorClassName"
  onEditorStateChange={this.onEditorStateChange}
toolbar={{
    inline: { inDropdown: true },
    list: { inDropdown: true },
    textAlign: { inDropdown: true },
    link: { inDropdown: true },
    history: { inDropdown: true },
    image: { uploadCallback: this._uploadImageCallBack },
    inputAccept: 'application/pdf,text/plain,application/vnd.openxmlformatsofficedocument.wordprocessingml.document,application/msword,application/vnd.ms-excel'
  }}
/>
         </header>
      </div>
    );
  }
}

export default App;
0
ответ дан viney kumar 29 March 2019 в 12:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: