pqina / react-filepond

🔌 A handy FilePond adapter component for React
https://pqina.nl/filepond
MIT License
1.87k stars 91 forks source link

[Bug] can't get metadata in server api #242

Closed zshnb closed 8 months ago

zshnb commented 8 months ago

Is there an existing issue for this?

Have you updated React FilePond, FilePond, and all plugins?

Describe the bug

this is what I use in my project

const FileUploadButton = ({
  className,
  onFinishParse,
}: FileUploadButtonProps) => {
  registerPlugin(FilePondPluginFileValidateType)
  registerPlugin(FilePondPluginFileMetadata)
  return (
    <FilePond
      server={{
        process: '/api/upload',
        fetch: null,
        revert: null,
      }}
      allowFileMetadata={true}
      allowMultiple={true}
      maxParallelUploads={1}
      acceptedFileTypes={['application/pdf']}
      labelIdle="拖拽或点击上传文件"
      className={className}
      labelFileProcessingComplete="上传完毕"
      labelFileProcessing="上传中"
      onprocessfiles={() => {
        console.log('process files')
      }}
      onprocessfilestart={(file) => {
        console.log(`file ${file.filename} process start`)
      }}
      onprocessfile={(error, file) => {
        if (!error) {
          console.log(`file ${file.filename} process finished`)
        }
      }}
    />
  )
}

export default FileUploadButton

how ever, I checked request body, there is no json

image

how can I get default file metadata in server?

Reproduction

const FileUploadButton = ({
  className,
  onFinishParse,
}: FileUploadButtonProps) => {
  registerPlugin(FilePondPluginFileValidateType)
  registerPlugin(FilePondPluginFileMetadata)
  return (
    <FilePond
      server={{
        process: '/api/upload',
        fetch: null,
        revert: null,
      }}
      allowFileMetadata={true}
      allowMultiple={true}
      maxParallelUploads={1}
      acceptedFileTypes={['application/pdf']}
      labelIdle="拖拽或点击上传文件"
      className={className}
      labelFileProcessingComplete="上传完毕"
      labelFileProcessing="上传中"
      onprocessfiles={() => {
        console.log('process files')
      }}
      onprocessfilestart={(file) => {
        console.log(`file ${file.filename} process start`)
      }}
      onprocessfile={(error, file) => {
        if (!error) {
          console.log(`file ${file.filename} process finished`)
        }
      }}
    />
  )
}

export default FileUploadButton

Environment

- Device: Mac
- OS: Mac
- Broser: Chrome
- React version: 18
rikschennink commented 8 months ago

With PHP you can get the metadata with $_POST['filepond'] and the file with $_FILES['filepond'], see: https://pqina.nl/filepond/docs/api/server/#process

zshnb commented 8 months ago

With PHP you can get the metadata with $_POST['filepond'] and the file with $_FILES['filepond'], see: https://pqina.nl/filepond/docs/api/server/#process

but you can see my screenshot, there is no metadata in payload?

rikschennink commented 8 months ago

afaik it doesn't show metadata there, it only appends metadata that is added to the file item, not the file information itself

zshnb commented 8 months ago

afaik it doesn't show metadata there, it only appends metadata that is added to the file item, not the file information itself

is there anyway to add file information to file item when upload?

rikschennink commented 8 months ago

see docs

zshnb commented 8 months ago

see docs

sorry I don't find it, could you please give me a link? I mean add automatically, not manually

rikschennink commented 8 months ago

https://pqina.nl/filepond/docs/api/plugins/file-metadata/

https://pqina.nl/filepond/docs/api/file-item/

https://pqina.nl/filepond/docs/api/instance/events/

Listen to "addfile" event then populate metadata with setMetadata