【问题标题】:FilePond only pdf accepted filesFilePond 仅接受 pdf 文件
【发布时间】:2020-09-27 02:25:12
【问题描述】:

我正在使用 FilePond (React) 来上传文件。我只想要pdf文件。 我已经使用 npm 命令安装了文件类型验证插件: npm i filepond-plugin-file-validate-type --save 然后 npm run-script build 命令。我已经测试过,它正在上传各种文件。

这是我的代码:

import {registerPlugin} from 'react-filepond'
// Import the plugin code
import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type';
// Register the plugin
registerPlugin(FilePondPluginFileValidateType);


 <FilePond
                        accepted-file-types={"application/pdf"}
                        server={{
                            process: async (fieldName, file, metadata, load, error, progress, abort) => {
                                await processFile(fieldName, file, metadata, load, error, progress, abort, setFileName);
                            }
                        }}
                        //server={{process: Config.pdfServer}}
                        //ref={ref => this.pond=ref} // To call instance methods
                        oninit={() => handleInit()}
                        // nom du fichier c'est file.name
                        // callback onupdatefiles- a file has been added or removed, receives a list of file items
                        onupdatefiles={(fileItems) => {
                            // Set current file objects to this.state
                            // boucler sur un tableau
                            setFile(fileItems.map(fileItem => fileItem.file));
                            //     console.log(fileItem.getFileEncodeBase64String());
                        }}
                        allowFileEncode={true}
                        allowMultiple={false}
                        instantUpload={true}
                        onprocessfile={(error, file) => {
                            console.log('PROCESSED', file, 'SERVER_ID', file.serverId);
                            //    console.log('ERROR PROCESSED', error);
                        }}
                        // callback tiré de la documentation FilePond - if no error, file has been succesfully loaded
                        onaddfile={(error, file) => {
                            console.log('PROCESSED', file, 'SERVER_ID', file.serverId);
                            //   console.log('ERROR PROCESSED', error);
                        }}
                    />

非常感谢。

编辑:接受文件类型={['application/pdf']} 无法正常工作...

【问题讨论】:

    标签: reactjs filepond


    【解决方案1】:

    你可以试试accepted-file-types={['application/pdf']},文档描述了必须为属性“accepted-file-types”指定一个数组。

    https://pqina.nl/filepond/docs/patterns/plugins/file-validate-type/

    编辑:

    您必须使用 CamelCase 作为属性。所以正确的设置可能是acceptedFileTypes={["application/pdf"]}

    【讨论】:

    • 非常感谢您的回答。我已经看过文档,我首先执行了accepted-file-types={['application/pdf']} run npm run-script build 命令,结果与它接受各种文件的结果相同。我不明白为什么这么奇怪......
    • 请编辑评论。我认为如果您将属性设置为 CamelCase 它应该可以工作
    猜你喜欢
    • 2020-08-19
    • 2014-09-10
    • 2011-09-06
    • 1970-01-01
    • 2023-01-04
    • 1970-01-01
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    相关资源
    最近更新 更多