Filepond, запрос DELETE и имя файла - PullRequest
0 голосов
/ 19 февраля 2020

У меня есть сервер, который прекрасно принимает запрос DELETE от Filepond. Тем не менее, мне трудно найти имя файла в запросе. После прочтения я обнаружил, что он находится в теле запроса DELETE. Это правда? Если так, как мой сервер получает к нему доступ? req.filename?

    if(typeofreq === 'DELETE'){
        var nameoffile = req.body; //<---??? How do I pull out the filename?
        if(nameoffile === undefined){
            res.err;
        }else{
            var fs = require('fs');   
            fs.unlinkSync('./assets/images/' + req.params(filename));  
        }
     }
---------------------FilePond React -----------

 <> <div className="Fileupload">         
         <FilePond ref={ref => this.pond = ref}
                      files={this.state.files}
                      name="avatar"
                      allowImageCrop={true}
                      allowMultiple={true}
                      method="POST"
                      maxFiles={5}
                      allowImageExifOrientation={true}
                      allowImagePreview={true}
                      imageResizeTargetWidth={600}
                      imageCropAspectRatio={1}
                      allowFileTypeValidation={true}
                      maxFileSize={10485760}
                      fetch={null}
                      revert={null}
                      allowFileEncode={true}
                      imageTransformVariants={{
                             "thumb_medium_": transforms => {
                                transforms.resize.size.width = 384;
                              return transforms;
                              },
                             'thumb_small_': transforms => {
                                transforms.resize.size.width = 128;
                              return transforms;
                             }
                          }
                       }
                      fileRenameFunction={ file => new Promise(resolve => {
                            resolve(window.prompt('Enter new filename', file.name)) })}
                      acceptedFileTypes="image/jpeg, image/png"
                      server= {{
                        url: "/photocontroller",
                        process: {
                            headers: {
                                'X-CSRF-TOKEN': '{{ csrf_token() }}'

                                //"X-CSRF-TOKEN": $('input[name="_token"]').val()
                            }
                        },
                        load:'/user/getphoto'

                      }
                     }  
                      oninit={() => this.handleInit() }
                      onupdatefiles={(fileItems) => {
                          // Set current file objects to this.state
                          this.setState({
                              files: fileItems.map(fileItem => fileItem.file)
                          });
                      }}>
            </FilePond>
      </div>
...