pqina / filepond

🌊 A flexible and fun JavaScript file upload library
https://pqina.nl/filepond
MIT License
15.16k stars 825 forks source link

addFile from Base64 image #431

Closed xnetdude closed 4 years ago

xnetdude commented 4 years ago

Hello fellow developer!

We are trying to populate filepond with an existing image on page load (asp.net core / Razor Pages) from our backend database using the addFile(s) approach in JQuery. We have tried various methods but without any luck, filepond just says error during load.

Does anyone know if we can pass a Base64 string into the "source" property of the AddFiles method, because we have tried and again failed eg this is our current attempt but we have also tried just using the actual base64 string and not an image object.

        var image = new Image();
        image.src = '@Model.Theme.LogoBase64';
        //pond.addFile(image);
        pond.files[]
        pond.addFiles([
            {
                source: image,
                options: {
                    type: 'local'
                }
            }
        ]);

@Model.Theme.LogoBase64' is replaced at run-time by the full string including "data:image/png;base64,blahblahblah'

Thanks.

James.

xnetdude commented 4 years ago

The issue was caused by the base64 image being encoded (by Asp,net Core) when surfaced in the html. Removed encoding and all working well.