Search code examples
filepond

How to define a function 'server.remove' identical to 'server.revert'


How to define a function 'server.remove' (removing local files) identical to 'server.revert'.

'server.revert' send 'DELETE' request to '/api' with filename in request body.

I do not quite understand how the function should be organized, try something like that, but it does not work:

mounted() { 
          this.server = {
            url: '/api',
            remove: (source, load, error, revert) => {
                revert(source);
                error('oh my goodness');
                load();
            },
            headers: { 
              Authorization: 'Bearer ' + this.token,
              },
          };
    },

Solution

  • See here for the function signature, so something like this:

    this.server = {
      remove: (source, load, error) => {
    
        const request = new XMLHttpRequest();
        request.open('DELETE', 'url-to-api/' + source);
    
        request.onload = function () {
          if (request.status >= 200 && request.status < 300) {
            load(request.responseText);
          } else {
            error('oh no');
          }
        };
    
        request.send();
      },
    }