首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FilePond仅接受pdf文件

FilePond仅接受pdf文件
EN

Stack Overflow用户
提问于 2020-06-08 07:03:01
回答 1查看 5.6K关注 0票数 5

我正在使用FilePond (反应)来上传文件。我只想要pdf文件。我已经安装了npm命令的文件类型验证插件: npm i filepond插件-文件验证类型-保存,然后npm运行脚本构建命令。我已经测试过了,它上传了各种各样的文件。

这是我的密码:

代码语言:javascript
复制
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);
                        }}
                    />

非常感谢。

编辑:与接受-文件类型={‘应用程序/pdf’}它不工作.

EN

回答 1

Stack Overflow用户

发布于 2020-06-08 07:12:07

您可以尝试accepted-file-types={['application/pdf']},文档描述了对于属性“接受-文件类型”,必须指定数组。

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

编辑:

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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62256687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档