3

I followed filepond doc about Setting Initial Files to prepopulat filepond. Now, I want to write a custom revert function in which I can use different function based on file origin.

The following is a hypothetical code to show what I want to achieve:

#hypothetical code         
     revert: (uniqueFileId, load, error) => {
            console.log('uniqueFileId is +' uniqueFileId);

            const origin = ? ; //cannot figure out how to get file origin.

            if (origin =='1'){ // origin is input
                // run default function to remove input file

            } else if (origin =='2'){ // origin is limbo
                // run custom function to remove limbo file from server
                }); 

            } else { // origin is local
                // run custom function to remove local file from server

            }
            error('oh my goodness');

            // Should call the load method when done, no parameters required
            load();
        },

Question 1: I cannot get origin of the file. I tried following code inside of revert function, none of them worked. How should I get the origin of the file?

    const origin = origin;
    console.log('origin is ' + origin); // console not printing anything, no error message.

    const origin1 = FilePond.getFile().origin;
    console.log('origin1 is ' + origin1);// console not printing anything, no error message.

Question 2: suppose i can get origin of the file, how should I write function to remove input file? (in the origin == 1 case)? One thing I found was that when I click cancel button on newly added file, the uniqueFileId was 'success'. I am not sure if this is the way it should be because the file hasn't been uploaded or I have done something wrong.

In the case of 'LIMBO', the uniqueFileId was correctly shown as the file name such as '1.jpg'. I was able to pass this Id to the server.

ha-neul
  • 3,058
  • 9
  • 24

1 Answers1

2

The server.revert function is only called for limbo origins and input files that have been processed. For local files the server.remove function is used. The origin is not available in the server methods.

If you do need it you could store a separate list of files and compare the file id. In the server.revert method you can then use that list to see what kind of file it is.

const myFiles = {
   'myuniquefileid': 'limbo',
   'myotheruniquefileid': 'local',
}

FilePond.create({
  server: {
    revert: (uniqueFileId, load, error) => {
      // origin
      const origin = myFiles[uniqueFileId];

      // more code

    }
  }
})
Rik
  • 3,328
  • 1
  • 20
  • 23
  • `@Rik` Thanks for pointing out that `revert` is for `limbo` origin! I should have used `local` rather than `limbo`. I was able to consult this github post (https://github.com/pqina/filepond/issues/192) to populate filepond with `local` files. – ha-neul Nov 10 '19 at 17:14