flat3/lodata

varbinary column breaks output

Closed this issue · 2 comments

Hi-- I have a column in my DB that's defined as varbinary(max). It's used to hold image data (I know, I don't like it much either).
When the odata controller tries to output this field it throws JsonException: Malformed UTF-8 characters, possibly incorrectly encoded -- is there a way to return this data properly, or if not, skip this field in the output? Thanks

Hi @thinkerytim, if you're using Lodata::discover() for your model but you want to un-discover this field, you can do something like:

Lodata::discover(User::class);
Lodata::getEntityType('User')->dropProperty('photo');

The OData protocol would say Lodata should base64-encode that field, and mark it as containing binary data in the metadata so the client understands how to decode it. Lodata does support Edm.Binary property data types, but it sounds like it's not assigning that type to a varbinary field type during discovery.

You could try hinting it: (I have not tested this, but I think it would work)

Lodata::discover(User::class);
Lodata::getEntityType('User')->getProperty('photo')->setType(Type::binary());

The type hinting worked perfectly. Thanks again for the quick help!