filepond
filepond copied to clipboard
File is of Invalid Type - Files prop doesn't support already processed mock files
Hey,
Thanks for your work. This is within a react application.
When I try to create a new FilePond instance and provide it a file prop from the controlled state of another FilePond instance it throws a 'File is of invalid type' error while looking like it attempts to make a get request to the current url + the source id or something. This only occurs when source FilePond state was created with a mock file. It looks like the mock file is processed and displayed correctly by the source FilePond but after post-processing by FilePond the mock file is not a Blob or File but a plain Object... so I think this issue is isolated to mock files. I'm unable to avoid passing a processed mock file.
Apologies if this is an issue you've already addressed.
Best,
rowrowrowrow
I'm not sure I understand the issue, can you create a test case on codesandbox.io that would be very helpful.
Sorry for the convoluted explanation. I'll work on an example if this psuedo-code doesn't help.
- const sourceFilePond = React.createElement(FilePond,{files : mockFiles});
- const processedMockFiles = sourceFilePondFiles; // Gathered from a parent component state of sourceFilePond
- let destinationFilePond = React.createElement(FilePond,{files : undefined});
- destinationFilePond = React.cloneElement(, {files:processedMockFiles });
Please create an example
Thanks for taking the time, I realized that this is the same issue as adding initial files using the addFiles method even though the files are passed as props. So I found a solution by recreating the initial files which is great.
But, not having to do that would be preferable :), e.g. if there was a way to specify/detect that the file was an initial mock file and not attempt to recreate/process it and whatever else happens. Of course I don't understand the implications of that as well as you but if you know of a way please let me know!!!!
@rowrowrowrow I don't think that's possible, maybe you can add metadata and remove it when it's no longer a mock file?
@rikschennink Ya I'm currently filtering mock vs. real using metadata because it's a simpler approach.
But, the processed mock file should have all the data to recreate itself internally or signal that it's an already processed mock file and prevent loading. E.g. I noticed the file property of a processed mock file is an Object and not a File or Blob... Something along these lines or just simply checking for a predetermined metadata property like 'isMockFile'. Happy to help work towards making this happen as I think it's weird that mock files can't persist like real files.