【问题标题】:How to include Attach File option in react-draft-wysiwyg?如何在 react-draft-wysiwyg 中包含附加文件选项?
【发布时间】:2018-12-04 10:21:25
【问题描述】:

我正在尝试使用 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、xls 等扩展名的文件作为附件。谁能指导我如何实现文件附件?

【问题讨论】:

    标签: reactjs wysiwyg draftjs draft-js-plugins


    【解决方案1】:

    您需要向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

    【讨论】:

    • 当我更改 inputAccept 时,我可以上传文件,但上传后显示为图像图标
    猜你喜欢
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多