eve-sqlalchemy
eve-sqlalchemy copied to clipboard
support of 'media' type fields / binary content columns
How would I define a column, so that eve handles it like a field of type 'media'? If I use sqlalchemy.sql.sqltypes.LargeBinary eve tries to interpret the data as a utf-8 encoded string and usually errors out, because the content is not valid utf-8.
I was checking out the media type (file) support with eve-sqlalchemy and turned out that the ValidatorSQL doesn't have that support yet. So for now, subclassing ValidatorSQL and adding the following method in it will bring support to uploading media/files -
from werkzeug.datastructures import FileStorage
class Validator(ValidatorSQL):
def _validate_type_media(self, field, value):
if not isinstance(value, FileStorage):
self._error(field, "file was expected, got '%s' instead." % value)
next thing is you'll have to make a type handler like eve.io.media.MediaStorage and provide it in the arguments of Eve instance as media=YourMediaStorage.
Not sure it will help you but thats how eve handles media type.
i have just made a pull request to support media type attribute.