eve-sqlalchemy icon indicating copy to clipboard operation
eve-sqlalchemy copied to clipboard

support of 'media' type fields / binary content columns

Open fiveop opened this issue 7 years ago • 2 comments

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.

fiveop avatar Dec 14 '17 09:12 fiveop

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.

asif-mahmud avatar Dec 16 '17 14:12 asif-mahmud

i have just made a pull request to support media type attribute.

asif-mahmud avatar Dec 16 '17 14:12 asif-mahmud