【问题标题】:How to get origin property of reverted file in filepond如何在filepond中获取还原文件的原始属性
【发布时间】:2023-03-11 04:29:01
【问题描述】:

我关注了关于将初始文件设置为预填充文件池的文件池文档。现在,我想编写一个自定义还原函数,在该函数中我可以根据文件来源使用不同的函数。

以下是显示我想要实现的假设代码:

#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();
        },

问题 1: 我无法获取文件的来源。我在revert函数中尝试了以下代码,但没有一个起作用。我应该如何获取文件的来源?

    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.

问题 2: 假设我可以获得文件的来源,我应该如何编写函数来删除输入文件? (在起源 == 1 的情况下)?我发现的一件事是,当我在新添加的文件上单击取消按钮时,uniqueFileId 为“成功”。我不确定这是否应该是因为文件尚未上传或我做错了什么。

在“LIMBO”的情况下,uniqueFileId 正确显示为文件名,例如“1.jpg”。我能够将此 ID 传递给服务器。

【问题讨论】:

    标签: filepond


    【解决方案1】:

    server.revert 函数仅针对 limbo 来源和已处理的输入文件调用。对于local 文件,使用server.remove 函数。源在服务器方法中不可用。

    如果您确实需要它,您可以存储一个单独的文件列表并比较文件 ID。在server.revert 方法中,您可以使用该列表查看它是什么类型的文件。

    const myFiles = {
       'myuniquefileid': 'limbo',
       'myotheruniquefileid': 'local',
    }
    
    FilePond.create({
      server: {
        revert: (uniqueFileId, load, error) => {
          // origin
          const origin = myFiles[uniqueFileId];
    
          // more code
    
        }
      }
    })
    

    【讨论】:

    • @Rik 感谢您指出revertlimbo 的来源!我应该使用local 而不是limbo。我可以查阅这篇 github 帖子 (github.com/pqina/filepond/issues/192) 来使用 local 文件填充文件池。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 2014-12-07
    • 1970-01-01
    • 2011-09-29
    • 2013-05-23
    • 2015-12-07
    相关资源
    最近更新 更多