【发布时间】: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']} 无法正常工作...
【问题讨论】: