如何在react-draft-wysiwyg中包含“附加文件”选项?

时间:2018-12-04 10:21:26

标签: reactjs wysiwyg draftjs draft-js-plugins

我正在尝试使用react-draft-wysiwyg创建一个文本编辑器。

编辑器代码

<Editor 
  editorState={this.state.editorState}
  onEditorStateChange={this.onEditorStateChange}
  toolbar={{
    options: ['inline', 'fontSize', 'fontFamily','list', 
            'textAlign', 'colorPicker', 'link', 'image'],
    link:{
        defaultTargetOption:'_blank',
        popupClassName:"mail-editor-link"
    },
    image:{
        urlEnabled: true,
        uploadEnabled:true,
        uploadCallback:this.uploadImageCallBack,
        alignmentEnabled: true,
        defaultSize: {
            height: 'auto',
            width: 'auto',
        },
        inputAccept: 'image/gif,image/jpeg,image/jpg,image/png,image/svg'
    }
  }}
/>

我想添加扩展名为pdfs,txt,docx,xl​​s的文件作为附件。谁能指导我如何实现文件附件?

1 个答案:

答案 0 :(得分:0)

您需要向inputAccept添加更多的MIME类型。

inputAccept: 'application/pdf,text/plain,application/vnd.openxmlformatsofficedocument.wordprocessingml.document,application/msword,application/vnd.ms-excel'

这是MIME类型的列表:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types