ctessier / nova-advanced-image-field

🌄 📐 A Laravel Nova advanced image field with cropping and resizing using Vue Advanced Cropper and Intervention Image
https://novapackages.com/packages/ctessier/nova-advanced-image-field
MIT License
100 stars 26 forks source link

Question: can i pass in base64 encoded data #109

Closed rabol closed 9 months ago

rabol commented 9 months ago

Hi

I have images saved as base64 encoded data in the db, is that supported by this field ?

ctessier commented 9 months ago

Hi @rabol, thank you for your message.

The Laravel Nova image field type doesn't support base64 out of the box. However, you should be able to make use of your base64 data using Laravel Nova native methods such as resolveUsing: https://nova.laravel.com/docs/resources/fields.html#field-resolution-formatting That would involve taking the base64 as the input, create a temporary binary file and return the file path so the image can be displayed.

Then, when saving a file, you can use fillUsing to take the file path as an input, and generate the base64 string to hydrate the model: https://nova.laravel.com/docs/resources/fields.html#field-hydration. As an alternative when saving, you can try to call ->convert('data-url'), and see what it does... This is provided by Intervention Image and made available by this package. I have never tried it though.

Hoping this help.