amidesfahani / filament-tinyeditor

a TineMce editor for Laravel Filament Forms
MIT License
46 stars 17 forks source link

Save image to base64 #46

Closed ronefel closed 1 month ago

ronefel commented 2 months ago

Is it possible to save the image in base64 in the database instead of saving it in storage?

Example: <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" width="313" height="269">

amidesfahani commented 1 month ago
images_upload_handler: (blobInfo, progress) => {
    return new Promise((resolve, reject) => {
        const reader = new FileReader();

        reader.onloadend = function() {
            // Get the base64 string
            const base64data = reader.result;
            resolve(base64data); // Return the base64 string to the editor
        };

        reader.onerror = function() {
            reject("Failed to convert image to base64.");
        };

        reader.readAsDataURL(blobInfo.blob());
    });
},