0

I've got a server that accepts the DELETE request from Filepond just fine. However, I am having a hard time trying to find the filename in the request. After reading, I found that it is in the Body of the DELETE request. Is that true? If so, how does my server access it? 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>
robert
  • 63
  • 7
  • In PHP it's possible to access the body of a DELETE request, not sure if this is possible in other server languages. As an alternative you can set up a custom `server.revert` end point and post the file id as a query string parameter. https://pqina.nl/filepond/docs/patterns/api/server/#advanced – Rik Feb 19 '20 at 08:59

1 Answers1

0

The problem was due to not using/understanding that axios doesn't use the body of the request but uses "data".

robert
  • 63
  • 7