pqina / filepond-plugin-image-transform

🖼 Client-side image transformations for FilePond
https://pqina.nl/filepond
MIT License
18 stars 8 forks source link

TypeError: Cannot read property 'data' of undefined - when outputting Base64 string #15

Closed tomeczekstecc closed 4 years ago

tomeczekstecc commented 4 years ago

Hi. I really hate when I can't use such awsome library. Its raelly graet!!! Thanks guys.

But lately I stuck ror 3 days...

I use getFileEncodeBase64String method on file item in react's file pond library, I get the result (proper Base64 string) and then the app crashes with warnings:

TypeError: Cannot read property 'data' of undefined getFileEncodeBase64String C:/dev/dokMenagier/client/node_modules/filepond-plugin-file-encode/dist/filepond-plugin-file-encode.js:69 66 | if (!query('GET_ALLOW_FILE_ENCODE')) return; 67 | 68 | item.extend('getFileEncodeBase64String', function() { > 69 | return base64Cache[item.id].data; | ^ 70 | }); 71 | item.extend('getFileEncodeDataURL', function() { 72 | return 'data:'
        <FilePond
          allowFileEncode={true}
          files={cover}
          // allowMultiple={true}
          server={null}
          instantUpload={false}
          onupdatefiles={fileItems =>
            onFileChange(fileItems[0])
          }
        ></FilePond>

and as a handler:

const onFileChange = fileEncoded => { if ( fileEncoded === null || fileEncoded === undefined || fileEncoded === '' || fileEncoded === {} ) { console.log('!!!'); } else { console.log(fileEncoded.getFileEncodeBase64String()); } };

There is a valid Base64String in a console but app breaks.

Any ideas?

rikschennink commented 4 years ago

I suspect the fileEncoded variable contains the fileItem object but the file hasn't been encoded yet.

I'd try this with the onaddfile or onpreparefile callback.

tomeczekstecc commented 4 years ago

Your answear was clear, Your answear was fast, Your answear was Correct!! Thank You!!!