我正在使用FilePond (反应)来上传文件。我只想要pdf文件。我已经安装了npm命令的文件类型验证插件: npm i filepond插件-文件验证类型-保存,然后npm运行脚本构建命令。我已经测试过了,它上传了各种各样的文件。
这是我的密码:
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’}它不工作.
发布于 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"]}
https://stackoverflow.com/questions/62256687
复制相似问题